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

点击按钮隐藏元素

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>
全部评论

相关推荐

不愿透露姓名的神秘牛友
06-29 17:30
找实习找着找着就要进入7月了,马上秋招也要开始了,找实习还有意义吗?
绝迹的星:有面就面, 没面上就当日薪4位数大佬免费培训, 面上了再考虑要不要实习
点赞 评论 收藏
分享
想按时下班的我在等o...:我投测试也是这个情况,不知道咋办了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务