我想过滤两个文本框之间的日期,我的问题是当我在第二个框中选择日期时,它不包括我选择的日期。
文本框的代码
<label for="from">From</label>
<input type="text" id="from" />
<label for="to">To</label>
<input type="text" id="to" />
用于脚本的datepicker
//function for datepicker and date range
$(function() {
$( "#from" ).datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 1,
onSelect: function( selectedDate ) {
$( "#to" ).datepicker( "option", "minDate", selectedDate );
}
});
$( "#to" ).datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 1,
onSelect: function( selectedDate ) {
$( "#from" ).datepicker( "option", "maxDate", selectedDate );
}
});
});
更新
$from = new Date(Date.parse($("#from").datepicker('getDate')));
$to = new Date(Date.parse($("#to").datepicker('getDate')));
这是它定义的方式
答案 0 :(得分:0)
您应该直接访问该值:
if ($("#from").val()) {
$filter.push({field: "DateEnrolled", operator: ">=", value: $("#from").val()});
}
if ($("#to").val()) {
$filter.push({field: "DateEnrolled", operator: "<=", value: $("#to").val()});
}