首页上一页 1 下一页尾页 1 条记录 1/1页
关于event对象的button属性
发表在其他语言图书答疑区
2014-09-05
是否精华
是
否
版块置顶:
是
否
老师您好:
我在学习《j呵vascript从入门到精通》一书时,发现无论如何调试,均只能捕获鼠标右键被点击的事件(event.button==2);其余状态都无法捕获,代码如下:
<html>
<head>
<title>Captive the mouse's Key</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
.STYLE1 {font-size: 12px}
-->
</style>
</head>
<script>
function gosite(){
var key=event.button;
if(key==1){
document.write("The Left key has been clicked!");
}
else{
if(key==2){
document.write("The Right key has been clicked!");
}
else{
if(key==3){
document.write("The Right and Left key have been clicked!");
}
else{
if(key==4){
document.write("The Middle key have been clicked!");
}
else{
if(key==5){
document.write("The Middle and Left key have been clicked!");
}
else{
if(key==6){
document.write("The Middle and Right key have been clicked!");
}
else{
if(key==7){
document.write("The Middle and Right and left key have been clicked!");
}
}
}
}
}
}
}
}
document.onmousedown=gosite;
</script>
<body>
<div style="font-family:Verdana, Geneva, sans-serif; font-size:16px; ">
<script language="javascript">
document.write("Please click the mouse and try")
</script>
</div>
</body>
</html>
我在IE11和Chrome下试过,都不行,网页只对鼠标右键有相应,不知是什么原因,特向您请教!
我在学习《j呵vascript从入门到精通》一书时,发现无论如何调试,均只能捕获鼠标右键被点击的事件(event.button==2);其余状态都无法捕获,代码如下:
<html>
<head>
<title>Captive the mouse's Key</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
.STYLE1 {font-size: 12px}
-->
</style>
</head>
<script>
function gosite(){
var key=event.button;
if(key==1){
document.write("The Left key has been clicked!");
}
else{
if(key==2){
document.write("The Right key has been clicked!");
}
else{
if(key==3){
document.write("The Right and Left key have been clicked!");
}
else{
if(key==4){
document.write("The Middle key have been clicked!");
}
else{
if(key==5){
document.write("The Middle and Left key have been clicked!");
}
else{
if(key==6){
document.write("The Middle and Right key have been clicked!");
}
else{
if(key==7){
document.write("The Middle and Right and left key have been clicked!");
}
}
}
}
}
}
}
}
document.onmousedown=gosite;
</script>
<body>
<div style="font-family:Verdana, Geneva, sans-serif; font-size:16px; ">
<script language="javascript">
document.write("Please click the mouse and try")
</script>
</div>
</body>
</html>
我在IE11和Chrome下试过,都不行,网页只对鼠标右键有相应,不知是什么原因,特向您请教!