js区分鼠标点击的是左键还是右键

onmousedown 事件有个 event.button 可以返回一个数值,根据数值判断取得用户按了那个鼠标键 
event.button==0 默认。没有按任何按钮。 
event.button==1 鼠标左键 
event.button==2 鼠标右键 
event.button==3 鼠标左右键同时按下 
event.button==4 鼠标中键 
event.button==5 鼠标左键和中键同时按下 
event.button==6 鼠标右键和中键同时按下 

event.button==7 所有三个键都按下 

兼容IE的写法:

e = e || window.event;

本文来自:标哥小站,原地址:https://blog.liunians.cn/?id=5

评论

暂无评论