我希望在他们的名字中添加编号的输入(已经成功),但如果为空(不能),也可以通过单击按钮来删除它们。使用此代码,所有搜索类输入都将被删除。我只想要删除空的。这是我的尝试:
<script type="text/javascript">
// contains the counter for elements added
window.__buttonClickCounter = 1;
// Keep reference to container
var c = document.getElementById('inputs');
// Click handler that appends to the contents of the container
var clickhandler = function () {
c.innerHTML = c.innerHTML + "<input class='search' style='margin-bottom:4px;' type='search' name='word" + window.__buttonClickCounter + "'/>";
window.__buttonClickCounter++;
$('#removebtn').click(function () {
$('.search').remove();
});
}
</script>
谢谢!