Home > Web Front-end > JS Tutorial > body text

JS method to obtain the key values ​​of the left and right mouse buttons_javascript skills

WBOY
Release: 2016-05-16 16:34:21
Original
1644 people have browsed it
function test() 
{ 
alert(event.x+" "+event.y); 
alert(event.button); 
} 
/*右键菜单不显示*/ 
document.oncontextmenu=function() 
{ 
return false; 
} 
/*document.onmousedown=function() 
{ 
if(event.button==1) 
{alert("left")} 
if(event.button==2) 
{alert("right")} 
}*/ 
document.onkeydown=function() 
{ 
alert(event.keyCode); 
} 
</script>
Copy after login

event.x mouse horizontal axis
event.y mouse vertical axis
event.keycode keyboard value
events.button==0 Default. No buttons were pressed.
events.button==1 left mouse button
events.button==2 Right mouse button
events.button==3 Press the left and right mouse buttons simultaneously
events.button==4 middle mouse button
events.button==5 The left and middle mouse buttons are pressed simultaneously
events.button==6 The right and middle mouse buttons are pressed simultaneously
events.button==7 All three keys pressed

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template