(@_@;)我是程序猿,我编程,我快乐,知识改变命运,技术成就梦想   oh yeah!合作VX "w6668263" 联系Email:ye583025823@126.com

div内的button的click会触发两次(防止事件冒泡)

<html xmlns="http://www.w3.org/1999/xhtml">
    
    <head runat="server">
        <title>阻止事件冒泡
        </title>
        <script type="text/javascript">
            function SayHello(e) {
                alert("Hello World");
                e = window.event || e;
                if (e.stopPropagation) {
                    e.stopPropagation();
                } else {
                    e.cancelBubble = true;
                }
            }
        </script>
    </head>
    
    <body>
        <form id="form1" runat="server">
            <div onclick="SayHello(event)" style="width:300px; height:300px; background-color:Green">
                <input type="button" value="click me" onclick="SayHello(event)" />
            </div>
        </form>
    </body>

</html>

 

posted on 2012-05-15 09:22  一个草率的龙果果  阅读(7184)  评论(1编辑  收藏  举报

导航