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="确认">
<div id="div1"></div>
<p>1111111111</p>
</body>
</html>

 

posted @ 2015-01-12 17:24  mayufo  阅读(207)  评论(0编辑  收藏  举报