<script src="js/delImg.js"> </script> </head> <body> <h2>喜欢的水果</h2> <input id="b1" type="button" value="删除图片" οnclick="delNode()" /> <img src="images/sixty1.jpg" id="sixty1" alt="水果" /> <img src="images/sixty2.jpg" id="sixty2" alt="果篮" /> </body>
js
function delNode(){ var dNode=document.getElementById("sixty1"); //访问被删除的节点 document.body.removeChild(dNode); //删除图片 }