更新时间:2023-10-29 08:52:40
尝试这样:
var initialized = false;
$(function(){
$(#txtDate)。focus();
$(#txtDate)。blur(function(){
if !初始化){
$(#txtDate)。datepicker({
autoOpen:false
});
initialized = true;
}
});
});
示例
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