关于JQuery的判断鼠标点击

在jquery中有一个方法可以判断鼠标右键,滑轮,左键被按下。

event.which

起初看一些这方法的说明都是说单击,用了click事件,就试了半天却发现左键可以返回1,滑轮可以返回2,唯独右键一直出现的是菜单栏。后来改用为mousedown和mouseup就可以清楚的判断,鼠标的事件了。

 

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<script type="text/ecmascript" src="jquery-1.11.3.min.js"></script>
<script type="text/ecmascript" src="JQuery.md5.js"></script>
<style>
*{
margin: 0px auto;
padding:0px;
}
.head{
width:300px;
height:200px;
border:1px solid;
}
.content{
width:50px;
height:50px;
}
</style>
</head>

<body>
<div class="head">
<div class="content">i am here</div>
</div>
<script type="text/javascript">
$(function(){

$(".content").bind("mousedown",function(event){
console.log(event.which);
}).bind("mouseup",function(){
console.log(event.which);
})
//event.target.某属性//获取被触发事件的元素属性
//event.preventDefault();//阻止默认事件的触发,点击提交链接跳
})
</script>
</body>
</html>

转载于:https://www.cnblogs.com/IsMyWay/p/4881475.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值