It is very simple to determine whether the pressed Enter:
function EnterPress(){
if( == 13){
...
}
}
IE6's onkeypress will accept the "Enter Event", while onkeydown will not accept it
IE8's onkeypress will not accept the "Enter Event", while onkeydown will accept it
...Don't worry about this, write both
<input type="text" onkeypress="EnterPress()" onkeydown="EnterPress()" />
However, when FF comes, there will be conflicts again. FF is both accepted by onkeypress and onkeydown.
At the same time, in order to obtain event under FF, it is necessary to write it like this:
function EnterPress(e){ //Passing in event
var e = e | ;
if( == 13){
...
}
}
Then, just pass the parameter event to any event and the other without passing the parameter, so FF can be executed only once:
&<input type="text" onkeypress="EnterPress(event)" onkeydown="EnterPress()" />
In summary, compatible with IE and FF:
<head>
<script>
function EnterPress(e){ //Passing in event
var e = e | ;
if( == 13){
("txtAdd").focus();
}
}
</script>
</head>
<body>
<input type="text" onkeypress="EnterPress(event)" onkeydown="EnterPress()" />
<input type="text" />
</body>
--by:Funny fantasy
Copy the codeThe code is as follows:
function EnterPress(){
if( == 13){
...
}
}
IE6's onkeypress will accept the "Enter Event", while onkeydown will not accept it
IE8's onkeypress will not accept the "Enter Event", while onkeydown will accept it
...Don't worry about this, write both
Copy the codeThe code is as follows:
<input type="text" onkeypress="EnterPress()" onkeydown="EnterPress()" />
However, when FF comes, there will be conflicts again. FF is both accepted by onkeypress and onkeydown.
At the same time, in order to obtain event under FF, it is necessary to write it like this:
Copy the codeThe code is as follows:
function EnterPress(e){ //Passing in event
var e = e | ;
if( == 13){
...
}
}
Then, just pass the parameter event to any event and the other without passing the parameter, so FF can be executed only once:
Copy the codeThe code is as follows:
&<input type="text" onkeypress="EnterPress(event)" onkeydown="EnterPress()" />
In summary, compatible with IE and FF:
Copy the codeThe code is as follows:
<head>
<script>
function EnterPress(e){ //Passing in event
var e = e | ;
if( == 13){
("txtAdd").focus();
}
}
</script>
</head>
<body>
<input type="text" onkeypress="EnterPress(event)" onkeydown="EnterPress()" />
<input type="text" />
</body>
--by:Funny fantasy