开发者

How do I prevent form input data from being reset when I remove and re-append the form element?

I have a form that needs to be appended elsewhere in the DOM, and when that occurs all form inputs return to their original values. Is 开发者_JAVA技巧there a way to retain the form input values when the form element is removed and re-appended? I'm using jQuery and the append() function.


This is what worked for me:

Before the form element is cloned using .clone(true):

$('#MyForm :input').each(function() { 
    $(this).data('val',$(this).val()); 
});

After the cloned form element is append()'d:

$('#MySameFormSomewhereElseInTheDOM :input').each(function() {
     $(this).val($(this).data('val')); 
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜