如何检测用户的点击来自何处

时间:2018-05-01 17:46:29

标签: javascript events click event-listener

有没有办法知道来自用户的点击是来自鼠标滚轮还是触控板按钮触控板按下< / strong>而不是总是假设用户点击鼠标左键单击?

1 个答案:

答案 0 :(得分:0)

  

尝试一下:

var body = document.getElementsByTagName('body')[0];

body.addEventListener('mousedown', function(e) {
  if (e.which == 1) {
    body.innerHTML = 'click';
  }

  else if (e.which == 2) {
    body.innerHTML = 'middle click';
  }
})
<html>
  <body>
    Click Here
  </body>
</html>