【发布时间】:2017-07-07 06:25:39
【问题描述】:
以下代码在 Firefox 中无法正常运行,但在 chrome 中运行良好。
$("#parent").click(function(){
alert("parent")
});
$("#child").click(function(){
event.stopPropagation();
alert("child")
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div style="width:500px;height:500px;background:red;" id="parent">
<div style="width:200px;height:200px;background:green; font-size:200px" id="child">
X
</div>
</div>
当我点击child时,firefox中触发了parent的click事件,child完全被忽略了。
我错过了什么吗?
我试图找到问题,但主要是关于传播的问题。
【问题讨论】:
-
打开开发者工具(Firebug),在控制台查看错误信息
标签: jquery firefox cross-browser click parent