我认为这个问题很好地解释了我想要实现的目标。我有这个代码:
<input type="date" data-role="datebox" data-options='{"mode": "datebox","noButton": true,"useDialogForceTrue": true, "useDialogForceFalse": false}' name="mydate" id="mydate" />
我想在用户打开输入数据选项中的日期框窗口时设置一些默认日期,这样就不需要另外一行代码了。
感谢。
答案 0 :(得分: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