2012-04-22 20 views
0

我有以下形式:如何克隆表單並使克隆函數與原始文件完全相同?

$(function() { 
$("#message").keyup(function() { 
var text_msg = $("#message").val(); 
    if(text_msg.length > 3 && text_msg.length <= 140) 
    { 
     $('#post').attr('disabled', ''); 
     $('#post').attr('value', 'Submit'); 
    }else{ 
     $('#post').attr('disabled', 'disabled'); 
     $('#post').attr('value', 'Wait...') 
     if(text_msg.length > 3 && text_msg.length > 140){ 
      alert('Your message exceeded the number of characters which is 140. Delete a few letters.'); 
     } 
    } 

}); 

});

 $(function() { 
$(".resp").click(function(){ 
    var idf = $(this).attr('id'); 
    newform = $("form#form-msg").clone(true); 
     $("#new-form-"+idf).append(newform);// These id's are generated dynamically 
    }); 
}); 

    <form method="post" name="form-msg" id="form-msg" action="javascript:func()"> 
     <textarea id="message" name="message"></textarea> 
     <input type="submit" value="wait..." id="post" align="left" disabled="disabled" /> 
    </form> 

<div id="new-form-1"></div> 
<div class="resp" align="center" id="1">Reply</div> 
<div id="new-form-2"></div> 
<div class="resp" align="center" id="2">Reply</div> 
<div id="new-form-3"></div> 
<div class="resp" align="center" id="3">Reply</div> 

當我克隆它並不像原來的工作表單,提交按鈕沒有被激活,而不是在一個國家提交表單。一切正常,克隆形式的輸入較少。我如何使克隆功能等同於原始功能?

回答

0

您需要刪除屬性而不是刪除它們,即使該屬性是空的,也會導致該按鈕被禁用。使用jQuery,這意味着$(...).removeAttr('disabled')而不是$(...).attr('disabled', '')

+0

有其他JQ代碼中的錯誤,修正這個錯誤,但我意識到,我不能在字段中輸入的值。 – Karra 2012-04-23 14:16:06