我的鼠标侧面有两个按钮,其默认行为是“后退”和“前进”。
我想知道的是是否可以在 JavaScript 中检测这些鼠标按钮的点击,或者这些按钮是否是类似于键盘的“播放”、“音量调高”和“无线开/关”的“特殊”按钮纽扣。
我不知道任何特定的鼠标事件。
但是,您可以通过检查以下内容轻松找到自己的答案:event
的对象mousedown
event. 全屏小提琴:http://jsfiddle.net/dWfDL/1/show/ http://jsfiddle.net/dWfDL/1/show/
var text = typeof document.body.textContent != "undefined" ? "textContent" : "innerText";
window.onmousedown = function(e){
//Inspect the `e` object, for example using a for(var i in e) loop, or:
//console.log(e);
var s = [];
for(var i in e){
try{
if(e[i] !== null){
if(i.toUpperCase() == i) continue; //Ignore constants
if(typeof e[i] == "function") continue; //Ignore functions
if(e[i].parentNode) continue; //Ignore elements
if(e[i] === window) continue; //Ignore Window
}
s.push(i + " =\t\t" + e[i]);
}catch(err){s.push(i + " \tERROR reading property.")}
}
e.preventDefault();
s = s.join("\n") + "\n\n";
document.body[text] = s + document.body[text];
}
//Double-click to wipe contents
window.ondblclick = function(){
document.body[text] = "";
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)