<!!DOCTYPE html><html> <head> <title>训练</title> <meta charset="utf-8" /> <script type="text/javascript"> function jarrem(x){ //var a=document.getElementById("bu"); var child=x.childNodes; if(child!=null&&child.length>0){ a.removeChild(child[0]); } else{ alert("no child"); } } </script> </head> <body > <div id="bu" style="border: 1px solid blue;padding: 15px ;align: center;padding: 100px;"> <input type="button" name="button" id="b1" value="1" /> <input type="button" name="button" id="b1" value="2" /> <input type="button" name="button" id="b1" value="3" /> <input type="button" name="button" id="b1" value="4" /> <input type="button" name="button" id="b1" value="5" /> <input type="button" name="button" id="b1" value="6" /> <input type="button" name="button" id="b1" value="7" /> <input type="button" name="button" id="b1" value="8" /><br> <input type="button" onclick="jarrem(document.getElementById("bu"))" value="del" style="width :100px; height :50px;" align="center"/> </div> </body></html>
2 回答
已采纳
qq_青枣工作室_0
TA贡献446条经验 获得超754个赞
我帮你修改了,你能看出差别吗?
<!DOCTYPE html> <html> <head> <title>训练</title> <meta charset="utf-8" /> <script type="text/javascript"> function jarrem(x){ //var a=document.getElementById("bu"); var child=x.childNodes; if(child!=null&&child.length>0){ while(child[0]&& child[0].nodeType!=1) x.removeChild(child[0]); x.removeChild(child[0]); } else{ alert("no child"); } } </script> </head> <body > <div id="bu" style="border: 1px solid blue;padding: 15px ;align: center;padding: 100px;"> <input type="button" name="button" id="b1" value="1" /> <input type="button" name="button" id="b1" value="2" /> <input type="button" name="button" id="b1" value="3" /> <input type="button" name="button" id="b1" value="4" /> <input type="button" name="button" id="b1" value="5" /> <input type="button" name="button" id="b1" value="6" /> <input type="button" name="button" id="b1" value="7" /> <input type="button" name="button" id="b1" value="8" /><br> <input type="button" onclick="jarrem(document.getElementById('bu'))" value="del" style="width :100px; height :50px;" align="center"/> </div> </body> </html>
右下角_
TA贡献1条经验 获得超0个赞
function jarrem(x){
//var a=document.getElementById("bu");
var child=x.childNodes;
if(child!=null&&child.length>0){
//a.removeChild(child[0]);//不细心啊
x.removeChild(child[0]);
}
else{
alert("no child");
}
}
添加回答
举报
0/150
提交
取消