zepto的clone方法於textarea和select的bug修復

(function($) {
    Zepto.fn.clone = function() {
        var result = $.fn.clone.apply(this, arguments),
            oldTextareas = this.find('textarea').add(this.filter('textarea')),
            resultTextareas = result.find('textarea').add(result.filter('textarea')),
            oldSelects = this.find('select').add(this.filter('select')),
            resultSelects = result.find('select').add(result.filter('select'));

        for (var i = 0, l = oldTextareas.length; i < l; ++i) $(resultTextareas[i]).val($(oldTextareas[i]).val());
        for (var i = 0, l = oldSelects.length; i < l; ++i) resultSelects[i].selectedIndex = oldSelects[i].selectedIndex;

        return result;
    };
})(Zepto);//clone時textarea和select的值丟失,zepto和jQuery都存在這個問題,解決辦法是在clone的時候從新賦值
相關文章
相關標籤/搜索