0
这里的代码和预览>>http://jsfiddle.net/shingou/PGFxZ/jQuery Mobile的Datebox日期范围差异
,你可以看到我使用jQuery Mobile的和jQuery插件datebox这一个。 我在这里有一个代码来获得这些日期之间的差异。
function parseDate(str) {
var mdy = str.split('/')
return new Date(mdy[2], mdy[0]-1, mdy[1]);
}
function daydiff(checkinDate, checkoutDate) {
return (checkoutDate-checkinDate)/(1000*60*60*24)
}
$('#checkoutDate, #checkinDate').live('change', function() {
$('#numNights').each(function() {
$(this).text(daydiff(parseDate($('#checkinDate').val()), parseDate($('#checkoutDate').val())));
});
});
显然,如果我们在这里更改日期格式。
jQuery.extend(jQuery.mobile.datebox.prototype.options, {
'dateFormat': 'mm/dd/YYYY',
'headerFormat': 'mm/dd/YYYY',
});
例如我们做出这样的:
jQuery.extend(jQuery.mobile.datebox.prototype.options, {
'dateFormat': 'ddd, dd mmm YYYY',
'headerFormat': 'ddd, dd mmm YYYY',
});
范围日期之间的差异将导致为NaN。
对此的任何解决方案都非常有用,这要归功于提前。
非常感谢! :竖起大拇指 – shingou 2012-01-04 09:44:34