Bug fixes of jquery clone method applied to textarea and select

Source: Internet
Author: User

The test found that the jquery clone method of textarea and select has a problem. When the textarea and select values are cloned, they will be lost. This is a bug of jquery, you can see the code, which is relatively simple. In the clone operation, the val value is assigned again. If you know this, you can simply write it yourself.

The clone page you want to use is OK.

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 );

Related Article

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.