Is there a way to clone form field values in jQuery or javascript?

后端 未结 7 595
礼貌的吻别
礼貌的吻别 2020-11-28 14:01

jQuery has a clone() function that clones the actual form with no problem, but it doesn\'t preserve any values that have been entered into the form.

Is

相关标签:
7条回答
  • 2020-11-28 15:04

    Found this problem and wrote this wrapper:

    $.fn.cloneField = function(withDataAndEvents) {
    var clones = [];
    this.each(function(){
        var cln = $(this).clone(withDataAndEvents);
        cln.val($(this).val());
        clones.push(cln.get(0));
    });
    return jQuery( clones ); }; 
    
    0 讨论(0)
提交回复
热议问题