标签:cti head var type charset html class cli onclick
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>js 事件event</title> <script> window.onload=function() { var button=document.getElementById("button"); var box=document.getElementById("box"); button.onclick=function(ev){ box.style.display="block"; var oEvent=ev||event; //兼容火狐,ie,谷歌 oEvent.cancelBubble=true; //取消事件冒泡 } document.onclick=function(ev){ box.style.display="none"; //var oEvent=ev||event; //alert(oEvent.clientX+","+ oEvent.clientY);//兼容火狐,ie,谷歌 } // var ss = document.childNodes[1].tagName; // alert(ss); //html } </script> </head> <body> <input type="button" value="按钮" id="button"> <div id="box" style="width:500px;height: 300px;background: gray; display: none"></div> </body> </html>
原声js,取消事件冒泡,点击按钮,显示box,点击屏幕其他地方,box隐藏
标签:cti head var type charset html class cli onclick
原文地址:https://www.cnblogs.com/quitpoison/p/9900648.html