2011-07-29 83 views
0

我試圖讓您的朋友字段(名稱+電子郵件)重複,當你點擊「添加另一個朋友」。 每次我嘗試克隆字段時,它都會包含我不想要的字段中的文本! 有沒有人有任何想法?jQuery克隆清除文本字段

jsFiddle

感謝提前:)

回答

0

嘗試設置領域value=''你把值之後,從他們

0

綁定一個click事件處理程序「添加另一個朋友」 <div>元素。在該事件處理程序中,您想要將另一行表單元素附加到<p>元素。

HTML:

<p id="friendlist">Friend 1 Name: 
    <input type="text" name="friend_name[]" class="friendid"> 
    Friend 1 Email: 
    <input type="text" name="friend_email[]" class="friendid"/></p> 

<div id="addanother">add another friend</div> 

<input type="submit" name="submit" /> 

你的jQuery:

$(function() { 
    var nextIndex = 2; 

    $("#addanother").click(function() { 
     var html = '<br />Friend ' + nextIndex + 'Name:'; 
     html += '<input type="text" name="friend_name[]" class="friendid" />' 
     html += 'Friend ' + nextIndex + 'Email:'; 
     html += '<input type="text" name="friend_email[]" class="friendid" />'; 
     $("#friendlist").append($(html)); 
     nextIndex++; 
    }); 
}); 

jsFiddle