Js press ENTER event, js press ENTER
The carriage return Event uses the HTML Event object and uses the keyCode to determine the key to be hit.
<Intput type = "text" onkeydown = "Click ()"> <script type = "text/javascript"> function Click () {if (event. keyCode = 13) {// press the Enter key // do something }}</script> or: <input type = "text" onkeydown = "if (event. keyCode = 13) {Click ()} "> <script type =" text/javascript "> function Click () {// do something} </script>
For Event reference: html dom Event object
For more information about keyCode, see the keyCode table.
How can I determine if he entered the Enter key in JS?
<Input type = "textbox" id = "textbox1" onkeypress = "CheckInfo"/>
<Script language = "javascript" type = "text/javascript">
Function CheckInfo ()
{
If (event. keyCode = 13)
{
Alert (textbox1.text );
}
}
</Script>
How to Write a carriage return keyboard event in js?
<Script type = "text/javascript" language = JavaScript charset = "UTF-8">
Document. onkeydown = function (event ){
Var e = event | window. event | arguments. callee. caller. arguments [0];
If (e & e. keyCode = 27) {// Press Esc
// What to do
}
If (e & amp; e. keyCode = 113) {// press F2
// What to do
}
If (e & e. keyCode = 13) {// enter key
// What to do
}
};
</Script>
As long as you define the actions of these keys, you press these keys in the browser to respond, compatible with all current browsers.