0
我遇到了jquery焦點問題。jquery遞歸集中在文本框無法正常工作
因此,這裏是我想要完成的任務:
爲了解決即佔位符的問題,我想集中到一個元素,然後對其進行模糊處理,使佔位符出現。我目前正在使用它的模式形式。
它在模態窗體的第一次加載時工作正常,但關閉窗體並再次打開它似乎不起作用。
到目前爲止,我已經縮小了焦點問題的焦點,而不是被$(「#element」)。focus()多次觸發。
這裏是爲了說明這個問題
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。
任何想法傢伙?
嗨@saman感謝您的快速反應。我之前已經嘗試過觸發器,但結果是一樣的。只有第一個焦點在第二個循環中執行。 – Ikoy
更新:嘗試用getElementById()。焦點替換.focus。它不工作。 – Ikoy