나는 다음과 같은 HTML이 -반복적으로 스캔 DOM 요소 - 자바 스크립트
<a>
<b>
....
.....
<input type="button" name="add" onclick="..." value="add another"/>
</d>
</b>
....
</a>
을 그리고 난 다음 JS 내가 형 버튼의 입력을 추가 할 지금
/**
* 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;
}
을 snippets- 사용 (제거 버튼) 위의 목록에 표시된 현재 버튼 옆에 있습니다. 나는 이것을 재귀 적으로 시도했다. 그러나 이것은 효과가 없습니다. 위의 코드에서 문제를 찾을 수 있습니까?
OP가 무엇을 잘못했는지 보여주는 것은 좋지만 jQuery와 같은 라이브러리를 사용하면 그런 종류의 코드를 작성할 필요가 없습니다. –
모두에게 감사드립니다. – Acn
@JuanMendes - 동의합니다. 그래서 jQuery 버전을 썼다. – jfriend00