Reputation: 13555
I would like to enter the form , when press enter the input box , it will submit the form
$('input[type=text]').keypress(function(event) {
if(event.which == 13) {
//enter pressed
active($(this));
}
});
Test it on android mobile, but the keypress can not detect the keycode
How to block this behavior? Thanks a lot
Upvotes: 0
Views: 39
Reputation: 2372
$("input:text").keypress(function(event) {
if (event.keyCode == 13) {
event.preventDefault();
active($(this));
}
});
There we use preventDefault
to block his default behavior.
Upvotes: 1
Reputation: 1539
$('input[type=text]').keydown(function(event) {
var keyCode = event.keyCode || event.which;
if (keyCode == 13) {
active($(this));
}
});
Upvotes: 1