您的位置:首页 > 其它

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

2012-05-15 09:22 316 查看
<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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: