仿淘宝关闭二维码
完成效果如下:
//css代码 .box{ position: relative; width: 74px; height: 88px; border: 1px solid #ccc; margin: 100px auto; font-size: 12px; text-align: center; color: blue; } .box img { width: 60px; margin-top: 5px; } .close-btn { position: absolute; top: -1px; left: -16px; width: 14px; height: 14px; border: 1px solid #ccc; line-height: 14px; font-family: Arial, Helvetica, sans-serif; cursor: pointer; } //html代码 <div class="box"> 二维码 <img src="../Picture/二维码.png"> <i class="close-btn">x</i> </div> //js代码 var btn = document.querySelector('.close-btn') var box = document.querySelector('.box') // 2.注册事件 程序处理 btn.onclick = function() { box.style.display = 'none' //隐藏二维码 }