开发者

Binding to key press doesn't work in IE8 and older

I have this code on my web page:

$(document).keypress(function(e){
    if (e.which == 13){
        if ($('#title').is(":focus"))
        {
            $("#save_post").focus().click();
            $('div .jqEasyCounterMsg').css('visibility','hidden');
        }
        else i开发者_开发问答f ($('#s').is(":focus"))
        {
            $("#searchAddress").focus().click();
        }
    }
});

This works in every single browser except older versions of IE (8 and older). What should I change to get this to work in those versions?


Place your event handler code within a $(document).ready(... block and it should work.

$(document).ready(function() {
    $(this).keypress(function() {
        ...
    });
});

See http://api.jquery.com/ready/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜