我使用的日期選擇器腳本javascript日期檢查進出控制
<script type="text/javascript">
var datefield=document.createElement("input")
datefield.setAttribute("type", "date")
if (datefield.type!="date"){ //if browser doesn't support input type="date", load files for jQuery UI Date Picker
document.write('<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" />\n')
document.write('<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"><\/script>\n')
document.write('<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"><\/script>\n')
}
</script>
<script>
if (datefield.type!="date"){ //if browser doesn't support input type="date", initialize date picker widget:
jQuery(function($){ //on document.ready
$('#data_inicial').datepicker();
$('#data_final').datepicker();
})
}
</script>
HTML
<input id="data_inicial" type="date" value="" name="txtCheckIn"/>
<input id="data_final" type="date" name="txtCheckOut"/>
如何控制檢查進出日期, 不允許用戶輸入的日期離開最古老的入口?
好了,第一步是嘗試比較吧,我看不出任何痕跡在你的代碼......也請注意,客戶端 - 端驗證僅用於UX目的;任何REAL驗證只能在服務器端完成。 –
這就是爲什麼我問!我不知道如何做驗證!我的代碼是正確的,但是我不知道如何驗證日期 – user3786372
那麼在互聯網上肯定有很多資源可以幫助您開始使用它,是否需要進行日期驗證或比較(您需要哪一個還不清楚我)。基本上,驗證規則非常簡單,只有閏年有點棘手。有了一套簡單的'if'子句,你應該通過它。即使您的語言不包含日期比較方法,比較也更簡單。長話短說:沒有問題不知道該怎麼做,但是你應該先做好這個想法,然後你會意識到它有多容易。 –