我注意到在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的更新日志中搜索了一下,但没有找到相关消息。
有人能解释一下这种行为吗?谢谢!