我正在尝试强制光标在值错误时返回到之前的输入。 这是我使用的脚本的更简单版本:
$('input:first-child').blur(function(e){
console.log('here');
$('input:first-child').focus();
});
当我点击另一个要聚焦的元素时,它会起作用,但是当我点击主体或另一个div元素时,它不起作用。为什么? 我有一个jsfiddle案例:http://jsfiddle.net/leyou/Zabn4/37/
编辑: 我在Chrome / Win7上测试,但是使用Firefox看起来更糟糕。它完全忽略了焦点()
答案 0 :(得分:6)
这是因为模糊尚未完成。用一个很小的超时做它会起作用:
$('input:first-child').blur(function(e){
setTimeout(function () { $('input:first-child').focus(); }, 20);
});
答案 1 :(得分:0)
试试这个
$('input:first-child').blur(function(e){
console.log('here');
setTimeout(function() { $('input:first-child').focus(); }, 500);
});