[英]jQuery Clone Clear Text Field
从字段中获取value=''
后,尝试将其设置为value=''
将点击事件处理程序绑定到“添加另一个朋友” <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++;
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.