Jquery 抓取有困难<;选择>;标记焦点事件

Jquery 抓取有困难<;选择>;标记焦点事件,jquery,html,jquery-selectors,Jquery,Html,Jquery Selectors,我现在正在扯头发。。。我不知道如何让jQuery$(“thing”)(“:focus”)选择器在我的代码中使用标记。以下是我所拥有的: <input id="uText" name="uText" type="text" required/> <select id="uCarrier" name="uCarrier" style="display: none;"> <option value="NULL" selected="selected">Sel

我现在正在扯头发。。。我不知道如何让jQuery
$(“thing”)(“:focus”)
选择器在我的代码中使用
标记。以下是我所拥有的:

<input id="uText" name="uText" type="text" required/>
<select id="uCarrier" name="uCarrier" style="display: none;"> 
   <option value="NULL" selected="selected">Select One</option>
   <option value="AT&amp;T">AT&amp;T</option>
</select>

有人能解决这个难题吗

这是因为
模糊事件在焦点转移到select元素之前触发。您可以使用demo fiddle中添加的日志语句查看事件序列

这里一个可能的解决方案是使用
setTimeout
检查
focus
条件,如下所示,它会将条件的执行延迟几毫秒,此时焦点会转移到目标元素

$("#uText").on("blur", function() {
    setTimeout(function(){
        if ( !$("#uCarrier").is(":focus") ){
            $("#uCarrier").stop(true).fadeOut(400);
            $($("#uText")).stop(true).show().delay( 400 ).animate({width: "96%"}, 400);
        }        
    }, 20)    
});

演示:

以下是您页面上的内容:

  • 您可以选择文本框
  • 选择后,使用
    onFocus
    处理程序显示
  • 您单击
    ,这会导致以下两种情况发生:
  • 运行其
    blur
    处理程序
  • 获得焦点
  • 所以Arun是对的:您只需要执行setTimeout,等待几毫秒,选择框就可以获得焦点D


    祝你的项目好运

    谢谢你解释这里的时间线。这有帮助!
    $("#uText").on("blur", function() {
        setTimeout(function(){
            if ( !$("#uCarrier").is(":focus") ){
                $("#uCarrier").stop(true).fadeOut(400);
                $($("#uText")).stop(true).show().delay( 400 ).animate({width: "96%"}, 400);
            }        
        }, 20)    
    });