格在我看來,我通過動態JS添加的div像這樣:刪除使用JavaScript
<div id="detail[0]">
<input name="detail.Index" type="hidden" value="0" />
<input name="detail[0].details_name" type="text" />
<input name="detail[0].details_value" type="text" />
<input class="btn" type="button" value="Delete" />
</div>
的問題是如何通過單擊DIV刪除按鈕刪除選定的一個?
的JavaScript,增加了新的div:
<script>
$(function() {
var i = 0;
$('.plus').click(function()
{
++i;
var html2add = "<div id='detail[" + i + "]'>" +
"<input name='detail.Index' type='hidden' value='" + i + "' />" +
"<input name='detail[" + i + "].details_name' type='text' />" +
"<input name='detail[" + i + "].details_value' type='text' />" +
"<input class='btn' type='button' value='Delete' />"+
"</div>";
$('#details_part').append(html2add);
})
})
'this.parentNode一個.remove()'? – Albzi
要刪除id detail [0]嗎? –
用'$(this).closest('div')'選擇'div',然後'remove()'。 –