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/
精彩评论