900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > html如何判断鼠标右键事件 javascript中如何获取鼠标的左键 右键 滚轮点击事件呢?...

html如何判断鼠标右键事件 javascript中如何获取鼠标的左键 右键 滚轮点击事件呢?...

时间:2022-07-16 05:54:46

相关推荐

html如何判断鼠标右键事件 javascript中如何获取鼠标的左键 右键 滚轮点击事件呢?...

摘要:

下文讲述js中获取鼠标左键,右键,滚轮点击事件的方法分享,如下所示;

实现思路:

1.绑定mousedown事件,

2.通过获取事件的中button属性值

当button=2,代表右键

当button=0,代表左键

当button=1,代表点击滚轮

例:

捕捉鼠标点击事件

js捕捉鼠标点击事件

div{

background-color:green;

color:white;

height:60px;

width:200px;

padding:8px;

}

window.onload = function(){

document.getElementById("divTest").onmousedown = function(e){

if(e.button ==2){

alert("点了右键");

}else if(e.button ==0){

alert("点了左键");

}else if(e.button ==1){

alert("点了滚轮");

}

}

}

请在此区域点击鼠标左键,右键,滚轮

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。