我想在页面加载时过滤日期范围基础并将其显示在页面上。日期正在自动填充,我的问题是在 JQUERY 中使用准备好的文档时无法过滤它,有什么想法吗?
代码:
<label for="from">Start date:</label>
<input type="text" style="width: 196px;" id="from" />
<label for="to">End date:</label>
<input type="text" style="width: 196px;" id="to" />
//function for datepicker and date range
$(function() {
$("#from").datepicker({
defaultDate: "-3w",
minDate: "-3w",
changeMonth: true,
numberOfMonths: 1,
onSelect: function(selectedDate) {
$("#to").datepicker("option", "minDate", selectedDate);
}
}).datepicker('setDate', '-3w');
$("#to").datepicker({
defaultDate: "+1w",
maxDate: "currentText",
changeMonth: true,
numberOfMonths: 1,
onSelect: function(selectedDate) {
$("#from").datepicker("option", "maxDate", selectedDate);
}
}).datepicker('setDate', '+1w');
});
功能尝试....在页面加载时进行调整
$(document).ready(function () {
$filter = new Array();
$from = new Date(Date.parse($("#from").datepicker('setDate', '-3w')));
$to = new Date(Date.parse($("#to").datepicker('setDate', 'currentText')));
$to = $to.setDate($to.getDate() + 1);
if ($("#from").val()) {
$filter.push({ field: "DateEnrolled", operator: "islessthanorequalto", value: $to });
}
if ($("#to").val()) {
$filter.push({ field: "DateEnrolled", operator: "isgreaterthanorequalto", value: $from });
}
var grid = $("#grid").data("kendoGrid");
grid.dataSource.load($filter);
});
});