js 区分鼠标左右键

在Js的鼠标事件中,通常需要区分鼠标各个键

区别的方法很简单,在鼠标事件对象event中有一个button属性表示当前鼠标键,还有一个属性叫buttons用来表示总共有几个鼠标键

 

 

[php] view plain copy
 
  1. document.body.onmousedown=function(event){  
  2.     if(event.button==0){  
  3.         alert("鼠标左键点击了")  
  4.     }  
  5. };  

 

posted @ 2017-01-14 16:29  天涯海角路  阅读(743)  评论(0)    收藏  举报