0

我想过滤两个文本框之间的日期,我的问题是当我在第二个框中选择日期时,它不包括我选择的日期。

文本框的代码

            <label for="from">From</label>

            <input type="text" id="from"  />

            <label for="to">To</label>

            <input type="text" id="to" /> 

对于脚本日期选择器

         //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')));

这就是它的定义

4

1 回答 1

0

您应该直接访问该值:

 if ($("#from").val()) {

     $filter.push({field: "DateEnrolled", operator: ">=", value: $("#from").val()});
 }

 if ($("#to").val()) {
     $filter.push({field: "DateEnrolled", operator: "<=", value: $("#to").val()});
 }
于 2012-10-18T18:00:22.210 回答