简体   繁体   English

用jQuery模糊焦点

[英]Blur focus with jQuery

I have a jQuery dialog that I've loaded content into. 我有一个将内容加载到其中的jQuery对话框。 When I display the dialog the focus is set to the first item displayed. 当我显示对话框时,焦点设置为显示的第一项。 Normally this is not a problem, but I would prefer that none of the items have explicit focus. 通常这不是问题,但我希望所有项目都没有明确的重点。 How can I blur the focus? 如何使焦点模糊? Or perhaps set it to the dialog itself? 还是将其设置为对话框本身?

The dialog's HTML ID is "dialog". 对话框的HTML ID为“对话框”。 I've tried $("#dialog").focus() and $("#dialog :button").blur() to no avail. 我试过$("#dialog").focus()$("#dialog :button").blur()无济于事。

Here's a picture of the dialog: 这是对话框的图片:

在此处输入图片说明

Calling Blur will trigger the blur event nothing else. 调用模糊将触发模糊事件。

For take the focus out the textbox try $("#dialog").click(); 要使焦点集中在文本框中,请尝试$(“#dialog”)。click();。

Like this? 像这样? http://jsfiddle.net/MatthewDavis/Dpk2j/2/ http://jsfiddle.net/MatthewDavis/Dpk2j/2/

$(document).ready(function () {
  // putting a value into a button we don't want focused
  $('#mybutton').val('Here I am.');
  // doing something visual to see when focus happens more clearly
  $("input").focus(function () {
    $(this).next("span").css('display','inline').fadeOut(1000);
  });
  // focus on the right input
  $('#dialog').focus();
});

Try this: 尝试这个:

http://jsfiddle.net/mE5fx/ http://jsfiddle.net/mE5fx/

 open:function(){
     $(this).attr('tabindex',-1).css('outline',0).focus(); 
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM