首页 > 解决方案 > 用于选择开始和结束日期的数据范围选择器

问题描述

我正在寻找一个日期范围选择器,其中第一次单击是选择开始日期,然后刷新日历,第二次单击是选择结束日期。我发现的所有日期范围选择器都有两个日历,其中包含要同时选择的开始日期和结束日期。

有没有人做过类似的事情。

任何建议或帮助将不胜感激。

提前致谢

标签: javascriptjqueryangularjsdatepickerangular-ui-bootstrap

解决方案


我想你正在寻找这个。

 $( function() {
       $( "#fromDate" ).datepicker({
        defaultDate: "+1w",
        changeMonth: true,
        numberOfMonths: 1,
       
        onClose: function( selectedDate ) {
            $("#toDate").datepicker("option", "minDate", selectedDate);
        }
    });
    $( "#toDate" ).datepicker({
        defaultDate: "+1w",
        changeMonth: true,
        numberOfMonths: 1,
        onClose: function( selectedDate ) {
            $( "#fromDate" ).datepicker( "option", "maxDate", selectedDate );
        }
    });
  } );
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>jQuery UI Datepicker - Default functionality</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <link rel="stylesheet" href="/resources/demos/style.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>
</head>
<body>
 
<p>From: <input type="text" id="fromDate"></p>
<p>To: <input type="text" id="toDate"></p>
 
 
</body>
</html>


推荐阅读