[英]How to prevent jQuery datepicker from popping up on initial page load but still scroll to datepicker textbox
我有類似於以下 Javascript 的內容:
$(function () {
$("#txtDate").focus();
$("#txtDate").datepicker({
...
autoOpen: false,
...
});
});
我想專注於頁面加載時的文本框,而不會彈出日期選擇器。 當前頁面加載時日期選擇器已經打開。
我需要能夠在頁面加載時將頁面滾動到該文本框,並且txtDate文本框具有焦點會很好,以便用戶可以輕松地切換到表單中的下一個輸入。
任何幫助將不勝感激。
編輯:
注意:必須在 IE 8-10 下工作
試試這個:
var initialized = false;
$(function () {
$("#txtDate").focus();
$("#txtDate").blur(function(){
if(!initialized){
$("#txtDate").datepicker({
autoOpen: false
});
initialized = true;
}
});
});
示例
這個 jQuery 有效:
$(function () {
$(".txtDate").focus();
setTimeout(function() {$(".txtDate").datepicker({
autoOpen: false
});},10);
});
這有點黑客 - 在綁定日期選擇器之前添加了 0.01 秒的延遲,因此焦點發生在日期選擇器綁定之前,因此不會觸發日期選擇器。 http://jsfiddle.net/pQALk/2/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.