JS_显示和隐藏图片(display的用法)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>显示和隐藏图片</title>
</head>
<body>
    <div>
        <img src="tao.png" >
        <button class="close-btn">点我</button>
    </div>

    <script>
        //获取元素
        var img = document.querySelector(‘img‘);
        var btn = document.querySelector(‘.close-btn‘);
        
        var flag = 0;
        //注册事件 程序处理
        btn.onclick = function(){
            if(flag == 0){
                img.style.display = "none";
                flag = 1;
            }else{
                img.style.display = "block";
                flag = 0;
            }
        }
    </script>
</body>
</html>

 

JS_显示和隐藏图片(display的用法)

上一篇:CSS学习11-盒子模型


下一篇:qml导入js添加别名