我有这样的剧本。如何继续添加功能:删除项目?
JS
counter = 0;
function action() {
counterNext = counter + 1;
document.getElementById("input"+counter).innerHTML = "<p><input type='text' name='data[]' class='name'> <a href='#' class='remove'><img src='remove.png' width='20' height='20' border='0' id='remove'/></a></p><div id=\"input"+counterNext+"\"></div>";
counter++;
}
HTML
<p>
<input type='text' name='data[]' class='name'>
<a href="javascript:action();">Add</a>
</p>
<div id="input0"></div>
有人可以帮助我......
答案 0 :(得分:0)
要删除项目,请更改以下代码:
<a href='#' class='remove'>
为:
<a href='#' onclick='this.parentElement.parentElement.removeChild(this.parentElement); return false;' class='remove'>