<body> <ol id="oList"> <li><a href="javascript:;">Black metal</a></li> <li><a href="javascript:;">Alternative metal</a></li> <li><a href="javascript:;">Thrash metal</a></li> <li><a href="javascript:;">Doom metal</a></li> <li><a href="javascript:;">Classical metal</a></li> <li><a href="javascript:;">Gothic metal</a></li> </ol> </body>
<script type="text/javascript"> onload=function(){ var oList = document.getElementById("oList"); var remove = oList.getElementsByTagName("a"); for(var i=0;i<remove.length;i++){ remove[i].onclick=function(){ oList.removeChild(this.parentNode);//通过a标签删除它的直接父节点 } } } </script>