SoFunction
Updated on 2025-03-01

A brief discussion on Javascript event objects

If it is a function bound to an event handler function, the browser will pass a parameter by default, and this parameter is the event object.

 = function() {
 alert(); //1
}

Because using this parameter is more troublesome in this way, we can pass a parameter evt to use it.

 = function(evt) {
 var e = evt || ;
 alert(); //0 is the left mouse button, 1 is the scroll wheel, and 2 is the right mouse button //Based on the upper left corner of the browser viewing area alert( + ',' + );
 //The resolution of the machine alert( + ',' + );
 // The position from the upper left corner of the screen alert( + ',' + );
}
//Detection button = function(evt) {
 alert(getKey(evt));
}
function getKey(evt) {
 var e = evt || ;
 var keys = [];
 if () {
 ('shift');
 }
 if () {
 ('ctrl');
 }
 if () {
 ('alt');
 }
 return keys;
}
//Keyboard event, keydown is to press any key, keyup is to bounce any key, keypress press character key trigger//Key code: Any key on the keyboard, fully compatible//Character encoding: keys of characters that can be output, IE is incompatible=function(evt){
 var e = evt || ;
 alert(); //keyCode returns the key code }
 = function(evt) {
 var e = evt || ;
 alert();  //charCode returns character key code }
 = function(evt) {
 var e = evt || ;
 alert();  // Select which element wherever you click target }

The above is all the content of this article. I hope that the content of this article will help you study or work. I also hope to support me more!