以下代碼在firefox中無法正常工作,但它在Chrome中的工作效果非常好。Firefox會忽略子級並在單擊事件時跳到父級
$("#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>
當我點擊這個孩子,在Firefox中被觸發父的單擊事件,孩子完全被忽略。
我錯過了什麼嗎?
我試圖找到問題,但有關傳播的問題大多存在。
開放開發工具(Firebug)並檢查控制檯中的錯誤信息 – Andreas