![](/img/trans.png)
[英]How do I display the number of days selected from two dates selected from Zebra Datepicker?
[英]How do I grab total number of days selected between two dates?
我有這個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>
然后我有一個文本框控件:
<asp:TextBox ID="numOfDays" class="fptextbox12" runat="server" style="width:60px;"></asp:TextBox>
用戶選擇開始日期和結束日期后,我們希望在此框中輸入總天數。
任何想法如何計算呢?
將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.