我試圖在模態顯示之後將注意力集中在輸入上。如何將重點放在模態輸入上?
到目前爲止我見過並嘗試過的解決方案和鏈接:How to focus on a form input text field on page load using jQuery?,Jquery Focus on input field,並且它們都不起作用。
我的代碼其實很簡單:
$input = $("#letter-change-text").find("input[type='text']");
$input.val($.trim("I am just testing!!"));
$("#letter-change-text").modal('show');
$input.focus(); // this should focus the textbox in order to allow immediately input by the user
可以在JSfiddle檢查這個問題。
我也沒有任何成功的嘗試:
setTimeout(function(){
$input.focus();
}, 0);
http://jsfiddle.net/nce5aau8/1/ – adeneo 2014-09-24 16:03:06
我認爲你必須要等到動畫完成集中輸入。嘗試增加'setTimeout'中的等待時間 – 2014-09-24 16:03:08
嘗試在顯示模式之後獲取輸入 - jqueryui可能會複製元素。 – 2014-09-24 16:05:26