Home  >  Article  >  Web Front-end  >  JavaScript determines whether to press the Enter key and resolves differences between browsers_javascript skills

JavaScript determines whether to press the Enter key and resolves differences between browsers_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:48:311186browse
Copy code The code is as follows:


  • < ;span class="overlabel" style="display: block;">Please enter the verification code




  • Copy Code The code is as follows:

    //Listen to the Enter key auto-submit event
    function keyboardEvent(event){
    var keyCode=event.keyCode ? event .keyCode:event.which?event.which:event.charCode;//Solve the difference between browsers
    if(keyCode==13){
    submitForm();
    }
    }

    jQuery discards the standard button attribute in favor of which, which is a bit puzzling.

    which is introduced by Firefox and is not supported by IE. The original intention of which is to obtain the key value (keyCode) of the keyboard.
    Which in jQuery can be the key value of the keyboard or the key value of the mouse.
    Statement:
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn