如何禁用内置HTML日历中的以前的日期

时间:2019-05-27 15:24:30

标签: java html calendar

我已经使用内置的html日历供用户选择他们希望预订的日期,因为现在用户可以预订过去的日期,这是不可能的。所以我需要知道如何在内置日历html中禁用以前的日期

Java脚本

var today = new Date();
var date = today.getDate();
var month = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();




if(date<10)
{
date='0'+date // gets the date
} 

if(month<10)
{
month='0'+month // gets the month 
} 

today = yyyy+'-'+month+'-'+date; // 



document.getElementById("CurrentDate").setAttribute("Today", today);

HTML

<table> 
<tr>
<td>Date of booking:</td>
<td><input id="CurrentDate" type="date" name="bookingday" Today="" 
size="20"  > </td>  <!-- passes over the javacript variables to disable 
bookings on previous dates-->
</tr> 

<script src="calendar.js"></script>


<td colspan="2"><input type="submit" value="Hire Car!"/></td> <!--Submit 
button send user choice to databse  -->
<tr>


<td colspan="2"><input type="reset" value="Clear"/></td> <!-- Reset 
button 
lets user reset what they entered  -->
</tr>
</table>

0 个答案:

没有答案