jQuery mobile Datebox日期范围差异
这是代码和预览>> 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。
任何解决方案都非常有帮助,提前致谢。
here are the codes and preview >> http://jsfiddle.net/shingou/PGFxZ/
as you can see I've used jquery mobile and jquery datebox plugin for this one.
and I've got a code here to get the difference between those dates.
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())));
});
});
obviously if we change the date format here.
jQuery.extend(jQuery.mobile.datebox.prototype.options, {
'dateFormat': 'mm/dd/YYYY',
'headerFormat': 'mm/dd/YYYY',
});
for example we make it like this:
jQuery.extend(jQuery.mobile.datebox.prototype.options, {
'dateFormat': 'ddd, dd mmm YYYY',
'headerFormat': 'ddd, dd mmm YYYY',
});
the difference between the range dates will result to NaN.
any solution on this is really helpful, thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Datebox 有一个
.data('datebox').theDate
函数来从输入中获取日期,这样您就不必解析它。我相应地修改了你的小提琴 http://jsfiddle.net/PGFxZ/3/
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/