相关疑难解决方法(0)

jQuery:在mousemove事件期间检测按下的鼠标按钮

我尝试检测哪个鼠标按钮 - 如果用户在jQuery下的mousemove事件期间按下了,但是我得到了模棱两可的结果:

no button pressed:      e.which = 1   e.button = 0
left button pressed:    e.which = 1   e.button = 0
middle button pressed:  e.which = 2   e.button = 1
right button pressed:   e.which = 3   e.button = 2
Run Code Online (Sandbox Code Playgroud)

码:

<!DOCTYPE html>
<html>
<head>
  <script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>

<input id="whichkey" value="type something">
<div id="log"></div>
<script>$('#whichkey').bind('mousemove',function(e){ 
  $('#log').html(e.which + ' : ' +  e.button );
});  </script>

</body>
</html>
Run Code Online (Sandbox Code Playgroud)

如何判断按下鼠标左键和没有按钮之间的区别?

jquery

69
推荐指数
4
解决办法
6万
查看次数

标签 统计

jquery ×1