Friday 9 December 2016
javascript - jQuery Event Keypress: Which key was pressed?
Answer
Answer
With jQuery, how do I find out which key was pressed when I bind to the keypress event?
$('#searchbox input').bind('keypress', function(e) {});
I want to trigger a submit when ENTER is pressed.
[Update]
Even though I found the (or better: one) answer myself, there seems to be some room for variation ;)
Is there a difference between keyCode
and which
- especially if I'm just looking for ENTER, which will never be a unicode key?
Do some browsers provide one property and others provide the other one?
Answer
Actually this is better:
var code = e.keyCode || e.which;
if(code == 13) { //Enter keycode
//Do something
}
Subscribe to:
Post Comments (Atom)
c++ - Does curly brackets matter for empty constructor?
Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...
-
A fair amount of the second act of The Dark Knight Rises has a class warfare plotline. This is foreshadowed in the trailers with Selina Ky...
-
i have added this sql in my code , function devenir_client_dataforform() { $type = $_POST['clientType']; //$produit...
-
I'm still trying to wrap my head around how the following expression results in undefined behavior: a = a++; Upon searching SO...
No comments:
Post a Comment