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

chi*_*ntu 11 jquery

这是我的代码:

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

在IE中,光标在"reporter"元素中不闪烁.在Chrome中,它是.

非常感谢!

Kee*_*ker 18

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

建议

window.setTimeout(function(){
   $('#reporter').focus();
}, 50);
Run Code Online (Sandbox Code Playgroud)

这使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();
    }
});
Run Code Online (Sandbox Code Playgroud)