Js press ENTER event, js press ENTER

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.