Javascript-Dom-删除

<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>

 

posted @ 2017-01-12 17:11  Western_Journalist  阅读(209)  评论(0编辑  收藏  举报