2017-04-01 262 views
0

我有輸入日期,其中包含開始日期和結束日期以過濾期間。我想讓開始日期是今天的日期,結束日期與開始日期或開始日期之後的一天相同。條件是如果我在01-04-2017選擇開始日期,我可以選擇01-04-2017或在結束日期輸入之後的日期。開始日期和結束日期datepicker

這就是我所做的,但仍然沒有給出最好的答案。

<div class="col-md-4"> 
    <div class="input-group input-daterange"> 
     <input type="text" name="from_date_alt" id="from_date_alt" class="form-control datepicker" placeholder="Start date" value=""> 
     <span class="input-group-addon">to</span> 
     <input type="text" name="to_date_alt" id="to_date_alt" class="form-control datepicker" placeholder="End date" value=""> 
    </div> 
</div> 

這是腳本。

var nowDate = new Date(); 
var today = new Date(nowDate.getFullYear(), nowDate.getMonth(), nowDate.getDate(), 0, 0, 0, 0); 

$(".datepicker").datepicker({ 
    format: 'yyyy-mm-dd', 
    startDate: today, 
    autoclose: true 
}); 

我該怎麼做?

回答

0

$(function() { 
 
    $("#datepicker").datepicker("option", "minDate", new Date(2017, 3 - 1, 31)); 
 
    });
<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> 
 
    <script> 
 
    $(function() { 
 
    $("#datepicker").datepicker(); 
 
    }); 
 
    </script> 
 
<p>Date: <input type="text" id="datepicker"></p>

我不明白,這樣的事情?

相關問題