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

JavaScript operates the Enter event of the keyboard (any keyboard event), compatible with multiple browsers_javascript skills

WBOY
Release: 2016-05-16 18:18:56
Original
1139 people have browsed it

Without further ado, here’s the code:

Copy the code The code is as follows:
 
document. onkeydown=function()
{
var EventUtil = {};
EventUtil.getEvent = function(){
if(window.event){return window.event;}
else{ return EventUtil.getEvent.caller.arguments[0];}
}
var button = document.getElementById("qw");
if(EventUtil.getEvent().keyCode==13)
{
button.click();
event.returnValue = false;
}
}


For comparison: uploading one does not support IE, but Support FireFox:
Copy code The code is as follows:

window.onkeydown=function()
{
var EventUtil = {};
EventUtil.getEvent = function(){
if(window.event){return window.event;}
else{return EventUtil.getEvent.caller .arguments[0];}
}
    //Bind your button event with id qw


Copy the code The code is as follows:

var button = document.getElementById("qw");
if(EventUtil.getEvent().keyCode==13 )
{
button.click();
event.returnValue = false;
}
}

Do you see any difference?
The above is for reference only.
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