jQuery递归专注于文本框不起作用



我在jQuery focus时遇到麻烦。

所以这是我想完成的:

要解决IE占位符问题,我想集中精力放在一个元素上,然后模糊以使占位符出现。我目前在模态形式上使用它。

它在模态表单的第一个负载上正常工作,但是关闭表单并再次打开它似乎不起作用。

到目前为止,我已经缩小了问题的范围,以免被$("#element")。focus()多次触发。

这是一个说明问题的小提琴

http://jsfiddle.net/ere2n/1/

JS:

var i = 5;
while(i>0){
    focusMe();
    i--;
}
function focusMe(){
    setTimeout(function(){
        $('#text1').focus().queue(function(){
        setTimeout(function() {
            $('#text2').focus().queue(function(){
                setTimeout(function(){$('#text1').focus();},100);
                setTimeout(function() {
                    $('#text2').focus();
                }, 300);
            })
        }, 300);
        });                
    },100);
}
$("#text1").focus(function(){
    $("#count1").html(($("#count1").html()*1) + 1);
});
$("#text2").focus(function(){
    $("#count2").html(($("#count2").html()*1) + 1);
});

html:

<input type="text" id="text1" />
<input type="text" id="text2" />
<input type="text" id="text3" />
<div id="count1">0</div>
<div id="count2">0</div>

表现得很有趣..

该功能的第一次执行很好。

但是,第二个执行仅执行第一个#text1焦点,从而产生的统计信息为6:2。

有什么想法?

.focus仅运行您在焦点事件上写的代码使用"触发"或使用getElementById()。focus

最新更新