JQuery-Mobile UI DatePicker设置特定的默认日期

我在尝试在JQuery Mobile的UI datepicker上设置默认日期时遇到问题。

有人可以帮忙吗?

这是完整的源代码:

     jQuery Mobile Framework - Datepicker      //reset type=date inputs to text $( document ).bind( "mobileinit", function(){ $.mobile.page.prototype.options.degradeInputs.date = true; });     $(document).ready(function() { var queryDate = new Date(); queryDate.setFullYear(2009,11,01); $('#date').datepicker({defaultDate: queryDate}); });    

jQuery UI's Datepicker Styled for mobile

The included files extend the jQuery UI datepicker to make it suitable for touch devices. This plugin is not included in jQuery Mobile by default, so you'll need to include the files yourself if you'd like to use them. Scroll down for usage instructions.

Usage Instructions

The datepicker auto-generates from a regular input element with a type="date" attribute.

 <label for="date">Date Input:</label> <input type="date" name="date" id="date" value="" /> 

We'd recommend wrapping the label and input in a fieldcontain div for presentation purposes, and these elements should be placed within a form element for C-Grade browser accessibility.

Note: This plugin is not included in jQuery Mobile by default, so you'll need to include the following files in order to use it:

 <link rel="stylesheet" href="jquery.ui.datepicker.mobile.css" /> <script src="jQuery.ui.datepicker.js"></script> <script src="jquery.ui.datepicker.mobile.js"></script> 

You'll also want to configure the page plugin to convert "date" input elements to "text" inputs after they're enhanced with our datepicker, so that no native datepicker will conflict with the custom one we're adding. To do this, bind to the "mobileinit" event and set input types of "date" back to text using the page plugin's options:

 <script> //reset type=date inputs to text $( document ).bind( "mobileinit", function(){ $.mobile.page.prototype.options.degradeInputs.date = true; }); </script> 

Be sure to place this event binding in a script that loads after jQuery, but before jQuery Mobile. Check this page's source for an example.

谢谢

你应该做:

 $(document).ready(function() { var queryDate = new Date(2009,11,01); $('#date').datepicker({defaultDate: queryDate}); }); 

就是这样。

希望这有助于干杯

如果要设置日历日期和输入文本日期,这是我找到的唯一解决方案:

 $.datepicker.formatDate('dd/mm/yyyy'); // my data format var d = new Date(); // today or other date var curr_date = ("0" + (d.getDate())).slice(-2); // two digits day var curr_month =("0" + (d.getMonth()+1)).slice(-2); // two digits month var curr_year = d.getFullYear(); $('#myDatePickerControl').datepicker({defaultDate: d}); // set input text $('#myDatePickerControl').val(curr_date+'/'+curr_month+'/'+curr_year); // set calendar control