首页 > 其他分享 >JS-二维码关闭案例

JS-二维码关闭案例

时间:2022-11-04 15:58:54浏览次数:53  
标签:none img 100px style JS 案例 二维码 var 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>Document</title>
    <style>
      img {
        position: relative;
        width: 100px;
        height: 100px;
      }
      i {
        position: absolute;
        top: 0;
        left: 0;
      }
    </style>
  </head>
  <body>
    <div>
      <img class="img" src="/img/bg4.png" alt="" />
      <i class="i">x</i>
    </div>
    <script>
	//获取img对象,赋值给一个变量里;
      var img = document.querySelector(".img");
	  //获取i对象,赋值给一个变量里;
      var i = document.querySelector(".i");
	  //当点击i时,img ,i 的display变为none;
      i.addEventListener("click", function () {
        img.style.display = "none";
        i.style.display = "none";
      });
    </script>
  </body>
</html>

 

标签:none,img,100px,style,JS,案例,二维码,var,display
From: https://www.cnblogs.com/ZhuAo/p/16858078.html

相关文章