any ideas why this not work?
$(document).ready(function ubsrt()
{
$(window).bind('keyup', function(e) { if (e.keyCode == '27')
{
$('body').append('focus window <br />');
$(window).focus();
$开发者_运维问答(document).focus();
} });
$('#test').focus();
});
example
http://jsbin.com/agayen/edit#previewI think what you're trying to do is to remove focus from the text box when you hit escape, so try this (in your event handler):
$(e.target).blur();
In this example focus never leaves from the window so you can't assign it back.
You could test to see if the target is valid for a blur call too - e.g. test if it's an input.
Yes, you don't need to give the function a name. There you are defining a function, not calling one:
Instead of:
$(document).ready(function ubsrt()
{
Use:
$(function ()
{
精彩评论