jQuery focus()不是专注于IE,而是在Chrome中

前端之家收集整理的这篇文章主要介绍了jQuery focus()不是专注于IE,而是在Chrome中前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
这是我的代码
  1. jQuery('#reporter').blur(function() {
  2. if(data.indexOf('['+jQuery('#reporter').val()+']') >= 0)
  3. {
  4. alert("Please do not select pseudo user as Reporter");
  5. jQuery('#reporter').focus();
  6. }
  7. });

在IE中,光标在“reporter”元素中不闪烁.在Chrome中.

非常感谢!

解决方法

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

建议

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

这给IE的时间集中其他控件,窃取焦点,然后将其添加到#reporter.

防止行动

  1. $('#reporter').blur(function(e) {
  2. if(data.indexOf('[' + jQuery('#reporter').val() + ']') >= 0) {
  3. alert("Please do not select pseudo user as Reporter");
  4. $('#reporter').focus();
  5. e.preventDefault();
  6. }
  7. });

猜你在找的jQuery相关文章