开发者

jQuery Chrome - disable enter key

开发者 https://www.devze.com 2023-03-05 01:51 出处:网络
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

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();.

0

精彩评论

暂无评论...
验证码 换一张
取 消