开始日期不得大于结束日期jQuery PHP

时间:2019-03-14 08:23:20

标签: javascript jquery

我有两个日期选择器,我希望开始日期不能大于结束日期或结束日期不能 少于使用jquery的开始日期, 我尝试使用以下代码,但对我不起作用,该怎么办?

Uncaught TypeError: Cannot read property 'target' of undefined

1 个答案:

答案 0 :(得分:1)

您可以使用onSelect事件

$(function() {
  $("#from").datepicker({
    defaultDate: "",
    maxDate: "+0d",
    changeMonth: false,
    numberOfMonths: 1,

    onSelect: function(selected) {
      $("#to").datepicker("option", "minDate", selected)
    }
  });

  $("#to").datepicker({
    defaultDate: "",
    maxDate: "+0d",
    changeMonth: false,
    numberOfMonths: 1,

    onSelect: function(selected) {
      $("#from").datepicker("option", "maxDate", selected)
    }
  });
});
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<input type="text" id="from" />
<input type="text" id="to" />

相关问题