简体   繁体   English

jQuery UI日期选择器不起作用

[英]Jquery UI date picker is not working

I use jquery ui to add date picker when i click on a text field. 当我单击文本字段时,我使用jquery ui添加日期选择器。 But it's Year and month selector are not working. 但是它的年和月选择器不起作用。 What is the mistake? 怎么了

function date() {

                                        $("#dob").datepicker();
                                        $("#dob").datepicker("show");
                                        $("#dob").datepicker({
                                            changeMonth: true,
                                            changeYear: true,
                                            yearRange: "1900:1996"
                                        });


                                    }

And my input field code is this 我的输入域代码是这样

<input type="text" onclick="date()" id="dob"/>

You need not to call a function on click of input and bind datepicker every time. 您无需单击输入就调用函数,而不必每次都绑定datepicker。 Also just one call is enough rather calling it three times. 同样,只打一个电话就足够了,而不是打三遍。

first call is binding datepicker with default setting 首次呼叫是使用默认设置绑定日期选择器

$("#dob").datepicker();

second call is to show datepicker, it is not required as on click of input it will popup automatically 第二个调用是显示日期选择器,它不是必需的,因为单击输入时它将自动弹出

$("#dob").datepicker("show");

and third call is to show datepicker with your options like show year and month 第三个调用是显示日期选择器以及您的选项,例如显示年份和月份

$("#dob").datepicker({
   changeMonth: true,
   changeYear: true,
   yearRange: "1900:1996"
});

And you need only third datepicker call for your requirement, Use below code 您只需要第三个datepicker调用即可,请使用以下代码

<input type="text" id="dob"/>

jQuery jQuery的

$(function(){
    $("#dob").datepicker({
       changeMonth: true,
       changeYear: true,
       yearRange: "1900:1996"
    });
});

Demo 演示

You can achieve by using the following code 您可以通过使用以下代码来实现

     <form>
        <fieldset> 
        <input type="text" id="datepicker"/>  
        </fieldset>
     </form>

The script as follows 脚本如下

    $("#datepicker").datepicker({
      changeMonth: true,
      changeYear: true,
      yearRange: "1900:1996"

    });

JSFIDDLE 的jsfiddle

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM