我在刪除克隆的元素div時遇到了問題。我的代碼是這樣的如何使用jquery刪除克隆的元素
<div id="item_details">
<table>
<tr>
<td><p class="label_text">Name:</p></td>
<td><input name="item_name[]" type="text" value="" id="item_name" class="input_text" style="width: 126px;" /></td>
<td><p class="label_text">Brand:</p></td>
<td><input name="item_brand[]" type="text" value="" id="item_brand" class="input_text" style="width: 126px;" /></td>
<td><p class="label_text">Model No:</p></td>
<td><input name="model_number[]" type="text" value="" id="model_number" class="input_text" style="width: 126px;" /></td>
</tr>
</table>
</div>
這裏有添加股利和刪除按鈕
<div id="new_item_details" class="new_item_details"></div>
<div style="display:none;" id="removeitem">
<p style="margin:0px 0px 0px 600px;">
<input type="button" name="remove_item" id="remove_item" value="Remove Item" class="cv-form-control button cv-submit">
</p>
</div>
<br/>
<p style="margin:0px 0px 0px 0px;">
<input type="button" name="add_item" id="add_item" value="Add New Item" class="cv-form-control button cv-submit">
</p>
和我的jQuery代碼
jQuery(document).ready(function() {
jQuery('#add_item').click(function() {
var button = $('#item_details').clone();
button.find('input').val('');
jQuery(".new_item_details").append(button);
jQuery('#removeitem').show();
});
jQuery('#remove_item').click(function (e) {
jQuery(".new_item_details:last").remove();
e.preventDefault();
});
});
使用這個我無法刪除克隆格設置正確。
能否請您解釋一下 '無法刪除克隆DIV正常。'? – 2014-10-17 10:02:01