Home > Web Front-end > JS Tutorial > Bug fixes for jquery's clone method applied to textarea and select_jquery

Bug fixes for jquery's clone method applied to textarea and select_jquery

WBOY
Release: 2016-05-16 16:43:05
Original
1303 people have browsed it

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);
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template