什么是event对象?
用来获取事件的相信信息。
例:(实现鼠标点击其他位置隐藏弹出框)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <title>Document</title> <style> *{ margin: 0; padding: ; } body{ padding: 100px; } #div1{ height: 300px; width: 100px; background-color: #ccc; display: none; } </style> <script> window.onload=function(){ var oBtn = document.getElementById('btn'); var oDiv = document.getElementById('div1'); oBtn.onclick=function(ev){ var oEvent = ev||event; oDiv.style.display='block'; //时间对象阻止冒泡 oEvent.cancelBubble=true; } document.onclick=function(){ oDiv.style.display='none'; } } </script> </head> <body> <input type="button" value="显示" id="btn" /> <div id="div1"></div> </body> </html>