第二个日期大于javascript中的第一个日期
问题描述:
我有2个日期输入,我想将min
的checkout
设置为值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
为输入。
任何建议将是伟大的谢谢你。
答
试试这个
<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
答
您的代码适用于设置最小值。使用第一个输入change
事件来更新第二输入最低,而不是click
:
的可能的复制[用JavaScript比较两个日期](http ://*.com/questions/492994/compare-two-dates-with-javascript) –