JQuery focus()不是专注于IE,而是专注于Chrome

时间:2011-11-03 14:28:54

标签: jquery

这是我的代码:

jQuery('#reporter').blur(function() {
            if(data.indexOf('['+jQuery('#reporter').val()+']') >= 0)
            {
                alert("Please do not select pseudo user as Reporter");
                jQuery('#reporter').focus();                    
            }               
        });

在IE中,光标在“reporter”元素中不闪烁。在Chrome中,它是。

非常感谢!

1 个答案:

答案 0 :(得分:18)

您需要稍后使用超时设置模糊。另一个控件可能首先执行焦点。

建议

window.setTimeout(function(){
   $('#reporter').focus();
}, 50);

这使IE有时间聚焦其他控件,窃取焦点,然后将其添加到#reporter

阻止行动

$('#reporter').blur(function(e) {
    if(data.indexOf('[' + jQuery('#reporter').val() + ']') >= 0) {
        alert("Please do not select pseudo user as Reporter");
        $('#reporter').focus();
        e.preventDefault();
    }
});
相关问题