我正在尝试使用 jQuery 1.9 添加和删除表单字段。它添加了一个字段就好了,但是当试图删除它时什么都没有发生。
这是HTML...
<div class="control-group spacing-top">
<label for="answer[]" class="control-label required">Answers</label>
<div id="answers" class="controls">
<div class="answer-holder input-append">
<input class="input-xxlarge" placeholder="Answer" name="answer[]" type="text" value="" id="answer[]"> <span class="add-on"><i class="icon-remove"></i></span>
</div>
</div>
<button class="button button-secondary answer-add"><i class="icon-plus"></i> Add Answer</button>
这是 jQuery ......
$(function () {
var i = $('.answer-holder').length;
$('.answer-add').on('click', function () {
$('<div class="input-append"><input class="input-xxlarge" name="answer[]" type="text" value="" id="answer_' + i + '"><button class="answer-delete">Remove</button></div>').appendTo($('#answers'));
i++;
return false;
});
$('.answer-delete').on('click', function () {
$(this).parent('.answer-holder').remove();
return false;
});
});
有人能帮助我吗?
谢谢