标签:
<div id="div"> <select id="stu" name="stuff_type"> <#list stuffType as st> <option value="${st.dict_code}"> ${(st.dict_name)!}</option> </#list> </select> 数量: <input name="apply_num" type="text" value="" id="apply_num" /> 备注: <input name="mark" type="text" value="" id="mark" /> </div> var i=1; function adddiv(){ var div1=document.getElementById("div"); var aNode = document.createElement("input"); aNode.setAttribute("type","button"); aNode.setAttribute("value","删除"); aNode.setAttribute("onclick","deldiv(‘div"+i+"‘)"); var clonedNode = div1.cloneNode(true); // 克隆节点 clonedNode.setAttribute("id", "div" + i); // 修改一下id 值,避免id 重复 i=i+1; clonedNode.appendChild(aNode); div1.parentNode.appendChild(clonedNode); // 在父节点插入克隆的节点 // } } //删除DIV function deldiv(nodeId){ alert(nodeId); //1.获取块节点 var div_2Node = document.getElementById(nodeId); //2.获取父节点, var parentNode = div_2Node.parentNode; //3.删除 parentNode.removeChild(div_2Node); }
标签:
原文地址:http://www.cnblogs.com/img-zoom/p/4432783.html