Javascript checks whether to press the Enter key and solves the differences between browsers _ javascript skills

Source: Internet
Author: User
This article mainly introduces how to determine whether to press the Enter key in javascript and solve the difference between browsers. For more information, see The Code is as follows:



  • Enter Verification Code




  • The Code is as follows:


    // Listen to the Enter key to automatically submit events
    Function keyboardEvent (event ){
    Var keyCode = event. keyCode? Event. keyCode: event. which? Event. which: event. charCode; // solves the problem of differences between browsers.
    If (keyCode = 13 ){
    SubmitForm ();
    }
    }


    JQuery discards the standard button attribute using which, which is a bit confusing.

    Which is introduced by Firefox, which is not supported by IE. Which is intended to get the keyCode of the keyboard ).
    In jQuery, which can be the key value of the keyboard or the key value of the mouse.
    Related Article

    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.