jquery's Clone method bug fix

Source: Internet
Author: User

Test found that textarea and select the jquery clone method has a problem, textarea and select the value of clone will be discarded, found that this is a jquery bug, can not see the code, relatively simple. It is in clone when the Val re-assignment, if you know this, it is easy to write their own.

It's OK to introduce 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);


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.