首页 > 代码库 > dom 冒泡事件

dom 冒泡事件

<!doctype html><html><head><meta charset="utf-8"><style>#div1{    height:200px;    width:100px;    border:1px #999999 solid;    display:none;    }</style><title>无标题文档</title><script type="text/javascript">    window.onload = function ()    {        var obtn = document.getElementById(‘btn‘);        var odiv = document.getElementById(‘div1‘);            obtn.onclick = function (ev)        {            var ev = ev || event;            ev.cancelBubble = true;            odiv.style.display = ‘block‘;        }                document.onclick = function ()        {            odiv.style.display = ‘none‘;        }    };</script></head><body><input type="button" id="btn" value="http://www.mamicode.com/确认"><div id="div1"></div><p>1111111111</p></body></html>

 

dom 冒泡事件