0

这是代码和预览>> http://jsfiddle.net/shingou/PGFxZ/

如您所见,我为此使用了 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。

对此的任何解决方案都非常有帮助,在此先感谢。

4

1 回答 1

2

Datebox has a .data('datebox').theDate function to get the date from the input so you wont have to parse it.

I have modified your fiddle accordingly http://jsfiddle.net/PGFxZ/3/

于 2012-01-04T09:41:17.227 回答