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

后端 未结 7 666
礼貌的吻别
礼貌的吻别 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 14:54

    Stemming from the notes, here's a solution. With the following form:


    This jQuery works, including the textareas:

    $( 'input#clone' ).click(
        function()
        {
          $( 'form#old textarea' ).text( $( 'form#old textarea' ).val() )
          $("form#old").clone().attr( 'id', 'new_form' ).appendTo("body")
    
        }
    )
    

    ​Demo: http://jsfiddle.net/Jux3e/

提交回复
热议问题