简体   繁体   English

focusout()和trigger。('focusout')不会导致输入失去焦点

[英]focusout() and trigger.('focusout') not causing input to lose focus

I'm using the jQuery UI modal dialog, and populating it with some form fields. 我正在使用jQuery UI模式对话框,并用一些表单字段填充它。 Because of this bug: http://bugs.jqueryui.com/ticket/4731 , the first input gains focus when the dialog opens. 由于这个错误: http//bugs.jqueryui.com/ticket/4731 ,第一个输入在对话框打开时获得焦点。 To get around that, I'm trying to blur the affected input when the dialog is opened. 为了解决这个问题,我打算在打开对话框时模糊受影响的输入。

The problem is that there exists other functionality which is called for this input on a .blur() , and I don't want to fire that functionality for this. 问题是,存在被称为用于在此输入其他功能.blur()不想火为此该功能。

So, I'm trying to use .focusout() and .trigger('focusout') to achieve the same effect, but with no results. 所以,我正在尝试使用.focusout().trigger('focusout')来实现相同的效果,但没有结果。

Doing either of these: 做其中任何一个:

$('#input-id').focusout();
$('#input-id').trigger('focusout');

does not actually cause the input to lose focus, where using .blur() is successful. 在使用.blur()成功的情况下,实际上并不会导致输入失去焦点。 Am I missing something, or is there another way to accomplish what I need? 我错过了什么,还是有另一种方法来完成我需要的东西?

如果你喜欢快速的javascript hack,你可以使用:

$(':focus').blur();

My suggestion would be to set the focus to some other element in the dialog when it is opened instead of setting textbox to blur. 我的建议是在打开对话框时将焦点设置到对话框中的其他元素,而不是将文本框设置为模糊。 This should overcome your problem. 这应该可以克服你的问题。

Hope this Helps!! 希望这可以帮助!!

Focusout does not cause the element to lose focus. Focusout不会导致元素失去焦点。 Instead focusout is triggered when an element loses focus. 相反,当元素失去焦点时会触发焦点。 Check out http://api.jquery.com/focusout/ 查看http://api.jquery.com/focusout/

我用它作为解决方法:

$('body').focus();

我使用它而不需要在selenium驱动程序中执行javascript:

field.send_keys :tab

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

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