It is very simple to determine if a carriage return is pressed:
Copy Code code as follows:
function enterpress () {
if (Event.keycode = = 13) {
...
}
}
IE6 's onkeypress will accept the "carriage return event" and onkeydown will not accept
IE8 onkeypress will not accept the "carriage return event", and OnKeyDown will accept
... Don't dwell on it, two of them.
Copy Code code as follows:
<input type= "text" onkeypress= "enterpress ()" onkeydown= "enterpress ()"/>
However, under the FF, there will be contradictions. FF is onkeypress and onkeydown accept the "carriage return event".
Also, to be able to obtain an event under FF, you need to write this:
Copy Code code as follows:
function Enterpress (e) {//Incoming event
var e = e | | window.event;
if (E.keycode = = 13) {
...
}
}
So, if you give any one event incoming parameter event, and another argument is not passed, you can have FF perform only once:
Copy Code code as follows:
&<input type= "text" onkeypress= "enterpress (event)" onkeydown= "enterpress ()"/>
In comprehensive, compatible with IE and FF:
Copy Code code as follows:
<script>
function Enterpress (e) {//Incoming event
var e = e | | window.event;
if (E.keycode = = 13) {
document.getElementById ("Txtadd"). focus ();
}
}
</script>
<body>
<input type= "text" id= "txtname" onkeypress= "enterpress (event)" onkeydown= "enterpress ()"/>
<input type= "text" id= "Txtadd"/>
</body>
--by: The Illusion of bubbles