Home >Web Front-end >JS Tutorial >Bug fixes for jquery's clone method applied to textarea and select_jquery
The test found that there is a problem with the jquery clone method of textarea and select. The values of textarea and select will be lost when cloned. It is found that this is a bug of jquery. If you can't get it, you can take a look at the code. It is relatively simple. Just reassign the value of val when cloning. If you know this, it will be easy to write it yourself.
Just import it into the clone page you want to use
jquery.fix.clone.js
(function (original) { jQuery.fn.clone = function () { var result = original.apply(this, arguments), my_textareas = this.find('textarea').add(this.filter('textarea')), result_textareas = result.find('textarea').add(result.filter('textarea')), my_selects = this.find('select').add(this.filter('select')), result_selects = result.find('select').add(result.filter('select')); for (var i = 0, l = my_textareas.length; i < l; ++i) $(result_textareas[i]).val($(my_textareas[i]).val()); for (var i = 0, l = my_selects.length; i < l; ++i) result_selects[i].selectedIndex = my_selects[i].selectedIndex; return result; }; }) (jQuery.fn.clone);