【发布时间】:2016-04-12 20:12:52
【问题描述】:
我有两个带有两个 div 的 jsfiddler 设置:
<div class="d1" style="background-color: red; position: fixed; top: 0; bottom: 0; right; 0; left: 0; right: 0;">
<div class="d2" style="width: 200px; height: 100px; background-color: green; position: relative; top: 100px; left: 100px;"></div>
</div>
$(function() {
$('.d1').on('click', function(event) {
alert('clicked on red');
});
$('.d2').on('click', function(event) {
alert('clicked on green');
});
});
<div class="d1" style="width: 200px; height: 100px; background-color: red; position: relative; top: 100px; left: 100px;">
</div>
<div class="d2" style="width: 200px; height: 100px; background-color: green; position: relative; top: 100px; left: 100px;"></div>
$(function() {
$('.d1').on('click', function(event) {
alert('clicked on red');
});
$('.d2').on('click', function(event) {
alert('clicked on green');
});
});
在这两种情况下,我都单击绿色 div,并且在不释放鼠标按钮的情况下移动指针以悬停在红色 div 上,然后释放按钮。在第一个设置中,为红色 div 触发了 click 事件,而在第二个设置中,它没有被触发。
为什么不一样?
【问题讨论】:
-
@Paulie_D,是的,但是如果为启动事件的元素触发警报,它也应该在第二种情况下发生,对吧?
-
@Paulie_D,是的!安静不明显!谢谢队友:)
-
一旦发布并接受答案,请不要更改问题。问一个新问题。
标签: javascript html css