js监听鼠标mousemove时如何判断鼠标左键中键右键状态

首先添加鼠标移动监听

document.addEventListener('mousemove',function(e){

console.log(e.button,e.buttons,e.which);

})

1.只判断左键中键右键其中一个按键状态

e.which=0;左键中键右键都没按下

e.which=1;左键按下

e.which=2;中键(即滚轮)按下

e.which=3;右键按下

若要同时判断左中,右中,左右键则使用e.buttons

相关推荐
Bert.Cai1 分钟前
Python type函数详解
开发语言·python
逆境不可逃1 分钟前
【从零入门23种设计模式16】行为型之迭代器模式
java·开发语言·数据结构·算法·设计模式·职场和发展·迭代器模式
geovindu2 分钟前
python: Singleton Pattern
开发语言·python·单例模式·设计模式
Ronin3057 分钟前
【Qt常用控件】按钮类控件
开发语言·qt·常用控件·按钮类控件
慧都小项8 分钟前
JAVA开发工具IntelliJ IDEA v2026更新前瞻:更优的交互视觉,编程体验升级
java·开发语言·intellij-idea
prince_zxill14 分钟前
Raspberry PI传感器数据上云:Python IoT集成
开发语言·python·物联网
etcix16 分钟前
go cli translator that use bing api and youdao api
开发语言·elasticsearch·golang
亚历山大海18 分钟前
AiPPT接口文件PHP版本全,智能生成PPT文件并下载
开发语言·ai·php
ノBye~19 分钟前
Spring的IOC详解
java·开发语言