EnterKey doesn't work sometimes in IE8 using jQuery keyPressed

In my HTML CSS:

.edit_field {
    height: 50px;
    width: 495px;
    line-height: 3.6;
}

HTML:

<textarea id="message" class='edit_field'>Enter message here</textarea>

javascrpt:

$('#message').keypress(function(event) {
    // not getting fired this block when I pressed enter key
    // For all other keys its got fired well.
    if(event.which == 13) {
        // -- -- --
     }
});

Are there any problems in my code or in my browser (IE8)?

+3
source share
3 answers

Try the following:

$('#message').keyup(function(e){
  if(e.keyCode == 13){
    //your code probably want e.preventDefault() as well
  }
});

I found that the keypress implementation is not so browser friendly. Just a thought.

Edit : Now I remember why this does not work in IE8. The enter key (key code 13) is considered a “Special key” (as well as other keys, such as the arrow keys on the keyboard). IE does NOT fire the Special Keys key event, so I had to use keyup.

You can find more information here: http://www.quirksmode.org/dom/events/keys.html

" "

+5

e., IE, e.keyCode, , , keydown() keypress(), IE.

. http://unixpapa.com/js/key.html.


jQuery keypress() ?

+3

, , onKeyDown() IE7. , . , onkeydown() HTML, , .

, <div> , . jsp , ,

0
source

Source: https://habr.com/ru/post/1796493/


All Articles