If the function is bound by the event handler, the browser will pass a parameter by default, which is the event object.
Document.onclick = function () { alert (arguments.length); 1}
Because arguments[0] This parameter is cumbersome to use, so we can pass a parameter evt for use.
function (evt) { var e = evt | | window.event; // 0 is the left mouse button, 1 is the scroll wheel, 2 is the right button // position based on the upper-left corner of the browser's visible area Alert (E.clientx + ', ' + e.clienty); // The resolution of the machine Alert (Window.screen.width + ', ' + window.screen.height); // position from the upper left corner of the screen Alert (E.screenx + ', ' + E.screeny);}
//Detection KeysDocument.onclick =function(evt) {alert (GetKey (EVT));}functionGetKey (evt) {varE = EVT | |window.event; varKeys = []; if(E.shiftkey) {Keys.push (' Shift '); } if(E.ctrlkey) {Keys.push (' Ctrl '); } if(E.altkey) {Keys.push (' Alt '); } returnkeys;}
//keyboard event, KeyDown is pressed any key, KeyUp is bouncing up any key, KeyPress press the character keys trigger//key code: Any key on the keyboard, fully compatible//character encoding: can output the character of the key, ie incompatibleDocument.onkeydown=function(evt) {varE = EVT | |window.event; alert (E.keycode); //keycode return key code}document.onkeypress=function(evt) {varE = EVT | |window.event; alert (E.charcode); //charcode return character key code}document.onclick=function(evt) {varE = EVT | |window.event; alert (e.target.innerhtml); //point to where Target selects which element}
JavaScript Event Object