Home >Web Front-end >JS Tutorial >In the text box, the js code for the event triggered by the enter key [compatible with multiple browsers]_javascript skills
In the text box, the js code for the event triggered by the enter key [compatible with multiple browsers]_javascript skills
WBOYOriginal
2016-05-16 18:25:24962browse
It is very simple to determine whether the pressed key is Enter:
function EnterPress(){ if(event.keyCode == 13){ ... } }
IE6’s onkeypress will accept the "Enter event" , and onkeydown will not accept IE8's onkeypress will not accept "Enter event", but onkeydown will accept ... Don't worry about this, just write both
However, when it comes to FF, there will be contradictions. FF accepts "Enter events" onkeypress and onkeydown. At the same time, in order to be compatible with FF, it can be obtained below event, you need to write it like this:
<script> <br>function EnterPress(e){ //Incoming event <br>var e = e || window.event; <br>if(e.keyCode == 13 ){ <br>document.getElementById("txtAdd").focus(); <br>} <br>} <br></script>
--by:Bubble Fantasy
Statement:
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