此处使用0的超时,以便在模糊控件之前按键有时间结束。这让我觉得这是实现这个目标的方法......
$(document).keypress(function(e){
if( e.keyCode === 13){
setTimeout(function(){
$('input').blur();
}, 0);
}
});
按下回车键时,什么是模糊控件的更好方法?
答案 0 :(得分:1)
此处您不需要setTimeout
:
$(document).keypress(function(e){
if( e.keyCode === 13){
$('input').blur();
}
});
的 The demo. 强> 的
答案 1 :(得分:0)
为什么不尝试使用keyup
事件,以便在用户释放密钥之前有一点时间。
$(document).keyup(function(e){
if( e.keyCode === 13){
$('input').blur();
}
});
<强> Check Fiddle 强>
答案 2 :(得分:0)
你可能会惊讶地发现没有零暂停的事情。 Chrome的最小超时值为8毫秒,Firefox的最小值为15毫秒。