jquery焦点不工作模糊

Man*_*anu 6 jquery

如果验证失败,我正在使用jquery将焦点放在模糊的文本框上.但它在IE中工作但没有工作FF.有什么建议?

$("#inputBoxId").blur(function () {
   if ($(this).val() < 10) 
      $("#inputBoxId").focus();

});
Run Code Online (Sandbox Code Playgroud)

Mar*_*man 13

看起来你需要根据这个问题使用setTimeout .由于您要立即将焦点放在元素上,因此您需要考虑元素首先离开焦点的时间.

$("#inputBoxId").blur(function() {
    if ($(this).val() < 10) {
        setTimeout(function() {
            $("#inputBoxId").focus();
        }, 100);
    }
});
Run Code Online (Sandbox Code Playgroud)

它在jsfiddle上运行的示例,在chrome dev通道,firefox和IE8上进行了测试.