jquery的clone无法成功复制textarea和select

原址:http://stackoverflow.com/questions/742810/clone-isnt-cloning-select-values

https://github.com/spencertipping/jquery.fix.clone

(function (original) {
  jQuery.fn.clone = function () {
    var resu<            = original.apply(this, arguments),
        my_textareas     = this.find('textarea').add(this.fi< er('textarea')),
        resu< _textareas = resu< .find('textarea').add(resu< .fi< er('textarea')),
        my_selects       = this.find('select').add(this.fi< er('select')),
        resu< _selects   = resu< .find('select').add(resu< .fi< er('select'));

    for (var i = 0, l = my_textareas.len >h; i  l; ++i) $(resu< _textareas[i]).val($(my_textareas[i]).val());
    for (var i = 0, l = my_selects.len >h;   i  l; ++i) {
      for (var j = 0, m = my_selects[i].options.len >h; j  m; ++j) {
        if (my_selects[i].options[j].selected === true) {
          resu< _selects[i].options[j].selected = true;
        }
      }
    }
    return resu< ;
  };
}) (jQuery.fn.clone);
直接在需要的页面引用这个js即可


最新回复(0)
/jishuwn56qUxVQoYyrhapgRyn_2FZNmkkZXsfCSdBZwVHF1AC8_3D4858564
8 简首页