2016-08-15 122 views
0

我有2个日期输入,我想将mincheckout设置为值checkin第二个日期大于javascript中的第一个日期

Check In 
<input type="date" id="checkIn" name="checkIn"> 

Check out 
<input type="date" id="checkOut" min="" name="checkOut"> 

这个想法是在用户输入第一个日期之后,签出日期大于签入日期。

我已经用这样的尝试(适用于电话号码,但没有日期)

function updatedate() { 
    var firstdate = document.getElementById("checkIn").value; 
    document.getElementById("checkOut").min = firstdate; 
} 

使用onclick为输入。

任何建议将是伟大的谢谢你。

+1

的可能的复制[用JavaScript比较两个日期](http ://stackoverflow.com/questions/492994/compare-two-dates-with-javascript) –

回答

0

试试这个

<label>Check In</label> 
<input type="date" id="checkIn" name="checkIn" onchange="updatedate();"> 

<label>Check out</label> 
<input type="date" id="checkOut" min="" name="checkOut"> 

-

function updatedate() { 
    var firstdate = document.getElementById("checkIn").value; 
    document.getElementById("checkOut").value = ""; 
    document.getElementById("checkOut").setAttribute("min",firstdate); 
    } 
+0

谢谢。很棒。 – Lachlanf

0

您的代码适用于设置最小值。使用第一个输入change事件来更新第二输入最低,而不是click

​​

相关问题