How to use jquery to determine which key to hit on the keyboard

Source: Internet
Author: User

Sometimes we need to determine which key we hit on the keyboard, which needs to query what the value of the key on the keyboard is, such as the ENTER key is 13.

Here's the jquery code, don't forget to refer to jquery package ha.

<script type= "Text/javascript" >
$ (document). KeyPress (function (event) {
var keycode = (event.keycode? event.keyCode:event.which);
alert (Event.which); Determine the value of the knock key
if (keycode = = ' 13 ') {//whether hit enter
$ ("#btn_login"). Click ();
}
});
</script>

When I hit the ENTER key, I can invoke the Click event with the ID btn_login button.

How to use jquery to determine which key to hit on the keyboard

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.