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