如何防止jquery datepicker在初始页面加载时弹出,但仍然滚动到datepicker文本框 [英] How to prevent jquery datepicker from popping up on initial page load but still scroll to datepicker textbox

查看:163
本文介绍了如何防止jquery datepicker在初始页面加载时弹出,但仍然滚动到datepicker文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有类似于以下JavaScript的东西:

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

我想在页面加载时专注于文本框,而不会弹出datepicker。目前,该页面加载了datepicker已经打开。



我需要能够让页面滚动到页面加载的文本框,这将是很好的> txtDate 文本框具有焦点,以便用户可以轻松地将该表单标签到下一个输入。



任何帮助将不胜感激。

编辑:

注意:必须在IE 8-10中工作

解决方案

尝试这样:

  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/

这篇关于如何防止jquery datepicker在初始页面加载时弹出,但仍然滚动到datepicker文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆