美文网首页
2018-11-28

2018-11-28

作者: 小城叙缘 | 来源:发表于2018-11-28 17:18 被阅读0次

    点击其他地方弹出框隐藏

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>testing</title> <style type="text/css"> #pop { border: #000; background-color: #CCC; position: absolute; left: 50px; top: 50px; width: 200px; height: 500px; display: none; } #btn { color: #f00; } </style> </head> <body> <span id="btn">点击打开</span> <div>其他内容</div> <div>其他内容000</div> <div id="pop"> 弹出框 <p> <a href="https://www.baidu.com" target="_blank">点击弹出层里面的a标签,弹出层也不会隐藏</a> </p> </div> </body> </html> <script type="text/javascript"> var btn = document.getElementById('btn'); var pop = document.getElementById('pop'); window.onload = function () { document.onclick = function (e) { pop.style.display = "none"; } btn.onclick = function (e) { pop.style.display = "block"; e = e || event; stopFunc(e); } pop.onclick = function (e) { e = e || event; stopFunc(e); } } function stopFunc(e) { e.stopPropagation ? e.stopPropagation() : e.cancelBubble = true; } </script>

    相关文章

      网友评论

          本文标题:2018-11-28

          本文链接:https://www.haomeiwen.com/subject/hejzqqtx.html