【发布时间】:2023-04-01 11:14:01
【问题描述】:
我有以下 html -
<a>
<b>
....
.....
<input type="button" name="add" onclick="..." value="add another"/>
</d>
</b>
....
</a>
而我使用下面的js sn-ps-
/**
* Dynamically add a remove button on next to the add button.
*
*/
addRemoveButton = function(node) {
if(node.nodeType == 3) {
if(node.nodeName == "input") {
if(node.getAttribute("type") == "button") {
if(node.getAttribute("name") == "add") {
var removeButton = node.cloneNode(true);
removeButton.removeAttribute("name");
removeButton.setAttribute("value", "remove");
removeButton.setAttribute("onclick", "");
removeButton.setAttribute("id", "");
(node.parentNode).appendChild(removeButton);
return;
}
}
}
}
if(node.nodeType == 1) {
var list = node.childNodes;
var i = 0;
while(i<list.length) {
return addRemoveButton(list[i]);
i++;
}
}
return;
}
现在我想在上面列表中显示的当前按钮旁边添加一个按钮类型的输入(删除按钮)。我试图递归地做到这一点。但这不起作用。你能从上面的代码中找到问题吗?
【问题讨论】:
标签: javascript jquery xml ajax dom