1

我认为这个问题很好地解释了我想要实现的目标。我有这个代码:

<input type="date" data-role="datebox" data-options='{"mode": "datebox","noButton": true,"useDialogForceTrue": true, "useDialogForceFalse": false}' name="mydate" id="mydate" />

当用户在输入数据选项中打开日期框窗口时,我想设置一些默认日期,这样它就不会占用另一行代码。

谢谢。

4

1 回答 1

1

HTML

<label for="mydate">Some Date</label>

<input name="mydate" id="mydate" type="date" data-role="datebox"
   data-options='{"mode": "calbox"}'>

<a href="#" id="linkmodelink">Open Link</a>

jQuery

$('#thisPageID').live('pagecreate', function(event) {
  // Default picker value of Jan 1, 2012
  var defaultPickerValue = [2012, 0, 1];

  // Make it a date
  var presetDate = new Date(defaultPickerValue[0], defaultPickerValue[1], defaultPickerValue[2], 0, 0, 0, 0);

  // Get Today
  var todaysDate = new Date(); 

  // Length of 1 Day
  var lengthOfDay = 24 * 60 * 60 * 1000; 

  // Get the difference
  var diff = parseInt((((presetDate.getTime() - todaysDate.getTime()) / lengthOfDay)+1)*-1,10); 

  // Set the origin date
  $('#mydate').data('datebox').options.defaultPickerValue = defaultPickerValue;

  // Set minDays to disallow anything earlier
  $('#mydate').data('datebox').options.minDays = diff; 
});

来源:http ://dev.jtsage.com/jQM-DateBox/demos/script/start.html

于 2012-04-24T16:02:16.473 回答