我想要达到的是使用 jQuery 生成动态文本框,因此,jQuery 代码:
var num = $('.question-container-1').length;
var newNum = new Number(num + 1);
var newElem = $('#question-container-' + num).clone().attr('id', 'question-container-' + newNum);
newElem.children('input[type=text]').val('');
$('#question-container-' + num).after(newElem);
和html代码:
<fieldset id="question-container-1" class="question-container-1">
<div class="control-group">
<label class="control-label" for="input01">Întrebare</label>
<div class="controls">
<input type="text" name="question" id="question-box" value=""/>
</div>
</div>
</fieldset>
<fieldset>
<div class="control-group">
<div class="controls">
<a href="#" id="add-question-1" class="add-question-1">Adaugă întrebare</a>
<a href="#" id="delete-question-1" class="delete-question-1" style="margin-left: 20px;">Șterge întrebare</a>
</div>
</div>
</fieldset>
毕竟,一切都很完美,除了一件事,它们是最后一个文本字段的克隆,但我也不想复制它的值,你怎么能看到我尝试使用子函数来查找文本字段,但是它不删除值