简体   繁体   English

添加jquery Datepicker后,文本框的初始值未显示

[英]Initial value for textbox doesnot show after I adding jquery Datepicker

I need to display initial value which selected from the database for the date text field.Im adding a date from jquery date picker. 我需要显示从数据库中为日期文本字段选择的初始值。我从jQuery日期选择器添加日期。 After I adding the jquery code Initial value does not show..Can anyone suggest me an answer? 添加jQuery代码后,初始值不显示。有人可以建议我答案吗? Thank you ! 谢谢 !

here is my jquery code 这是我的jQuery代码

<script src="JDate/ui/jquery.ui.core.js"></script>
    <script src="JDate/ui/jquery.ui.widget.js"></script>
    <script src="JDate/ui/jquery.ui.datepicker.js"></script>
    <link rel="stylesheet" href="JDate/demos/demos.css">
    <script>
    $(function() {
        $( "#birthday_text" ).datepicker();

        $( "#birthday_text" ).datepicker( "option", "dateFormat", "yy-mm-dd" );

    });

</script>

here is my textbox code 这是我的文本框代码

<input name="birthday_text" type="text" class="textfield" id="birthday_text" autocomplete="off" value="0000-00-00" readonly="readonly"/>

Initialize the default date when you attach the date picker as so: 附加日期选择器时初始化默认日期,如下所示:

$(function() {
  $( "#birthday_text" ).datepicker( {defaultDate:"0000-00-00",dateFormat: "yy-mm-dd" });

});​

jsfiddle with demo jsfiddle与演示

Update : Since you say that the "defaultDate" parameter is giving you problems, try this alternative: 更新 :由于您说“ defaultDate”参数给您带来了问题,请尝试以下替代方法:

  $( "#birthday_text" ).datepicker({dateFormat: "yy-mm-dd" } );
  $( "#birthday_text" ).val('0000-00-00');

jsfiddle for alternative. jsfiddle作为替代。

You'll want to set the default date with the options when you're setting the datepicker up. 在设置日期选择器时,您需要使用选项设置默认日期。 Check out their docs on default date: http://jqueryui.com/demos/datepicker/#option-defaultDate . 在默认日期查看他们的文档: http : //jqueryui.com/demos/datepicker/#option-defaultDate Also, there is a chance that the datepicker control won't let you use 0000-00-00 since it isn't a valid date. 此外,由于日期选择器控件不是有效日期,因此有可能不允许您使用0000-00-00。 Have you tried with something other than all zeros? 您是否尝试过除全零以外的东西?

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

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