【发布时间】:2017-03-31 15:59:11
【问题描述】:
我注意到在 Firefox 上的鼠标右键会触发一个 addEventListener。
我在更多浏览器和更多操作系统(IE 11-10-9、Safari、Chrome)上尝试了此代码,并通过按鼠标右键单击,仅在 Firefox 上始终打印 console.log 消息。
<div id="one-div" style="height:400px;width:500px;background-color:#000;"> click me </div>
<script>
function cb(event, from){
// if click is fired on <div> with:
// left click, both EventListener will be printed.
// right click, only the 'document' one will be printed.
event.preventDefault();
console.log(event + ' from: ' + from );
}
document.addEventListener('click', function(e){
cb(e,'document');
}, false);
document.getElementById("one-div").addEventListener('click', function(e){
cb(e,'one-div');
}, false);
</script>
我还注意到,当点击进入 div 时,它只会触发 document.addEventListener。 我搜索了 Firefox 更新日志,但没有关于此的消息。
谁能解释这种行为? 谢谢!
【问题讨论】:
标签: javascript firefox mouse right-click