且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何防止jquery datepicker在初始页面加载时弹出,但仍然滚动到datepicker文本框

更新时间:2023-10-29 08:52:40

尝试这样:

  var initialized = false; 
$(function(){
$(#txtDate)。focus();
$(#txtDate)。blur(function(){
if !初始化){
$(#txtDate)。datepicker({
autoOpen:false
});
initialized = true;
}
});
});

示例



http://jsfiddle.net/pQALk/3/


I have something similar to the following javascript:

$(function () {
    $("#txtDate").focus();
    $("#txtDate").datepicker({
        ...
        autoOpen: false,
        ...
    });
});

I want to focus in on the textbox on page load without having the datepicker pop up. Currently the page loads with the datepicker already open.

I need to be able to have the page scroll to that textbox on page load and it would be nice for the txtDate textbox to have focus so that users can tab to the next input in the form easily.

Any help would be greatly appreciated.

EDIT:
NOTE: must work in IE 8-10

Try this:

var initialized = false;
$(function () {
    $("#txtDate").focus();
    $("#txtDate").blur(function(){
        if(!initialized){
            $("#txtDate").datepicker({
                autoOpen: false
            });    
            initialized = true;
        }
    });
});

Example

http://jsfiddle.net/pQALk/3/