Fork me on GitHub

onclick阻止冒泡

 

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<div style='background:red;width:200px;height:50px' onclick='a()'>
    <input type='button' value='ok' onclick='b(event)'></input>
</div>
<script type="text/javascript">
     function a(e){
        console.log("div")
    }
    function b(e){
        console.log(e);
        if(e&&e.stopPropagation){
            e.stopPropagation();
        }else{
            window.event.cancelBubble =true;
        }
     }
</script>
</body>
</html>

 

 

 

posted @ 2019-01-22 14:27  森海轮回  阅读(1815)  评论(0编辑  收藏  举报