Mouse events are the most common type of event on the Web, after all, the mouse is still the most important positioning device. Then through the event object can get to the mouse button information and screen coordinate acquisition and so on.
One, the mouse button
The Click event is triggered only when the primary mouse button is clicked (usually the left button of the mouse), so it is not necessary to detect the button's information.
For MouseDown and MouseUp events, however, there is a button property in their event object that represents the press or Release button.
<script type= "Text/javascript" > function() { function (EVT) { var e = evt | | window.event; // achieve cross-browser compatibility Get event object alert (e.button) ;}; </script>
In the vast majority of cases, we only use the primary and secondary three click Key, IE given the other key combinations are generally not available. So, we just need to do these three kinds of compatibility can.
<script type= "Text/javascript" >functionGetbutton (evt) {//Cross-Browser right-click the appropriate varE = EVT | |window.event; if(EVT) {//Chrome Browser supports web and IE returnE.button;//be aware of the Order of Judgment}Else if(window.event) {Switch(E.button) { Case1 : return0; Case4 : return1; Case2 : return2; } }} window.onload=function() {document.onmouseup=function(EVT) {//called if(Getbutton (evt) = = 0) {alert (' Press the left button! ‘); }Else if(Getbutton (evt) = = 1) {alert (' Pressed the middle button! ‘); }Else if(Getbutton (evt) = = 2) {alert (' Press the right button! ‘ ); } }; };</script>
Second, visual area and screen coordinates
The event object provides two sets of properties for the browser coordinates, one for the left side of the page's visual area, and the other for screen coordinates.
<script type= "Text/javascript" > function() { function (EVT) { var e = evt | | window.event; + ', ' + e.clienty); + ', ' + e.screeny); }; }; </script>
Third, modifier keys
Sometimes, we need to use some keys on the keyboard to match the mouse to trigger some special events.
These keys are: Shfit, Ctrl, Alt, and meat (Windows keys in Windows, CMD in Mac), which are often used to modify mouse events and behavior, so they are called modifier keys. (combined with mouse)
<script type= "Text/javascript" >functionGetKey (evt) {varE = EVT | |window.event; varKeys = []; if(E.shiftkey) {Keys.push (' Shift ');//adding elements to an array } if(E.ctrlkey) {Keys.push (' Ctrl '); } if(E.altkey) {Keys.push (' Alt '); } returnkeys; } window.onload=function() {Document.onclick=function(evt) {alert (GetKey (EVT)); }; };</script>
JavaScript Event Object _ mouse Event