题解 | #点击按钮隐藏元素#

点击按钮隐藏元素

https://www.nowcoder.com/practice/9b0016737b3040aaa61316890f1ac3f8

<!DOCTYPE html>
<html>
    <head>
        <meta charset=utf-8>
        <style type="text/css">
            .box {
                width: 100px;
                height: 100px;
                border: solid 1px black;
                /*补全代码*/
                position: relative;
            }
            .btn{
                position: absolute;
                right: -10px;
                top: -10px;
                width: 20px;
                height: 20px;
                background-color: red;
                /*补全代码*/
                text-align: center;
                line-height: 20px;
            }
        </style>
    </head>
    <body>
 
        <div class='box'>
            <div class='btn'>X</div>
        </div>
 
        <script type="text/javascript">
            var btn = document.querySelector('.btn');
            var box = document.querySelector('.box');
            btn.onclick = function(){
                // 补全代码
                box.style.display = 'none'
            }
        </script>
    </body>
</html>
全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务