[英]How do I grab total number of days selected between two dates?
I have this jquery script that allows a user to choose a start date and end date: 我有这个jquery脚本,它允许用户选择开始日期和结束日期:
<script type="text/javascript" charset="utf-8">
$(document).ready(function () {
$('#txtToDate').datepicker({ showOn: 'button',
buttonImage: 'images/20/calendar200.gif',
buttonImageOnly: true, onSelect: function () { },
onClose: function () { $(this).focus(); }
});
$('#txtFromDate').datepicker({ showOn: 'button',
buttonImage: 'images/20/calendar200.gif',
buttonImageOnly: true, onSelect:
function (dateText, inst) {
$('#txtToDate').datepicker("option", 'minDate', new Date(dateText));
}
,
onClose: function () { $(this).focus(); }
});
$('#txtToDate').datepicker({
// Your other options here
onSelect: function(dateText, inst) {
var days = ($("#txtToDate").datepicker('getDate') -
$("#txtFromDate").datepicker('getDate'))/(24*60*60*1000);
$('#numOfDays').val(days);
console.log(days);
}
}
);
});
</script>
Then I have a textbox control: 然后我有一个文本框控件:
<asp:TextBox ID="numOfDays" class="fptextbox12" runat="server" style="width:60px;"></asp:TextBox>
Once a user chooses a start date and an end date, we would like the total number of days in that box. 用户选择开始日期和结束日期后,我们希望在此框中输入总天数。
Any ideas how to calculate this? 任何想法如何计算呢?
Add the onSelect
option to the datepicker and calculate the number of days. 将
onSelect
选项添加到日期选择器,然后计算天数。
$('#txtToDate').datepicker({
// Your other options here
onSelect: function(dateText, inst) {
var days = ($("#txtToDate").datepicker('getDate') -
$("#txtFromDate").datepicker('getDate'))/(24*60*60*1000);
$('#numOfDays').val(days);
}
}
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.