点击li里的隐藏超链接,将ul里的li隐藏

<!-- 点击li里的隐藏超链接,将ul里的li隐藏
1. 使用for获取ul的子节点,当点击隐藏按钮时,li消失
 -->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        window.onload = function () {
            var oUl = document.getElementById("Ul");
            var aA = oUl.getElementsByTagName("a");

            for (var i = 0; i < aA.length; i++) {
                aA[i].onclick = function () {
                    this.parentNode.style.display = "none";
                }
            }
        }
    </script>
</head>

<body>
    <ul id="Ul">
        <li>dfgf<a href="javascript:;" id="1">隐藏</a></li>
        <li>gjkfukfuk<a href="javascript:;" id="2">隐藏</a></li>
        <li>ghjfghjghgfhjghjgh<a href="javascript:;">隐藏</a></li>
        <li>xfgxhgfhg<a href="javascript:;">隐藏</a></li>
        <li>fhjdfhjhf<a href="javascript:;">隐藏</a></li>
    </ul>
</body>

</html>
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页