How Can I Prevent the Enter keypress from Triggering a Button Click?
I have the following code snippet.
$("#days").key开发者_StackOverflowpress(function(e){
if(e.keyCode == 13){
self.validateNightModalForm();
}
});
basically, it checks for enter then invoke a function.
My only problem is that IE8 also clicks a button. When I hit enter. I've checked it with all other browsers, but only IE8 does this.
Is there any way to prevent it?
Try adding those two lines:
if (e.keyCode == 13) {
self.validateNightModalForm();
e.preventDefault()
return false;
}
Hopefully this will stop the keypress event from "going up" and trigger the form submit.
精彩评论