mousedown事件
| event.button | IE | Firefox | Chrome | Opera |
| 左键 | 1 | 0 | 0 | 0 |
| 右键 | 2 | 2 | 2 | 2 |
| 中键 | 4 | 1 | 1 | 1 |
| 默认 | -- | -- | -- | -- |
测试代码:
IE:document.onmousedown = function(){console.log(window.event.button)} (注:IE不支持window.onmousedown)
non-IE: document.onmousedown = function(e){console.log(e.button)}
mouseup事件
| event.button | IE | Firefox | Chrome | Opera |
| 左键 | 1 | 0 | 0 | 0 |
| 右键 | 2 | 2 | 2 | 2 |
| 中键 | 4 | 1 | 1 | -- |
| 默认 | -- | -- | -- | -- |
测试代码:
IE:document.onmouseup = function(){console.log(window.event.button)}(注:IE不支持window.onmouseup)
non-IE: document.onmouseup = function(e){console.log(e.button)}
本文详细介绍了不同浏览器下鼠标点击事件(mousedown和mouseup)中event.button属性的具体表现,并提供了屏蔽鼠标右键的方法。

648

被折叠的 条评论
为什么被折叠?



