I've got a tutorial based web page, where users can advance to the next tutorial page by using arrow href buttons (only if they complete some tasks). Also on most pages the enter key will advance you to th开发者_开发百科e next page.
However, some tutorial pages, use the enter key for different purpose, and i want that key to be disabled. I've done the following:
$(window).keyup(function(e) {
if (e.keyCode == 13)
{
e.preventDefault();
return false;
}
});
which works fine in IE/FF/Opera but it doesnt in chrome.
In chrome, if i add an alert inside if, then the form will not submit. otherwise it will.
Any idea?
$(function () {
$('form').bind("keypress", function (e) {
if (e.keyCode == 13) return false;
});
});
Try to change window
to "form"
.
Also consider adding e.stopPropagation();
.
精彩评论