它也適用於java腳本。我從我的'表單'中調用了一個java腳本。這是解決方案。它按我的預期工作。
形式
<form name="purchase" id ="purchase" method="post" action="" onsubmit="return checkform()">
<div class="form-group">
<div class="input-group col-sm-4">
<div class="input-group-addon">Transaction Date <i class="fa fa-calendar"></i></div>
<input id ="txndt" class="form-control" type="date" max="<?php echo date("Y-m-d")?>" name ="purch_date" value="<?php echo $query2['purch_date'] ?>" onblur = "txn40();" required />
</div>
</div>
</form>
Java腳本
<script type="text/javascript">
function checkform()
{
var dateString = document.purchase.txndt.value;
var myDate = new Date(dateString);
var today = new Date();
if (document.purchase.txndt.value == "")
{
//something is wrong
alert('REQUIRED FIELD ERROR: Please enter date in field!')
return false;
}
else if (myDate>today)
{
//something else is wrong
alert('You cannot enter a date in the future!')
return false;
}
// if script gets this far through all of your fields
// without problems, it's ok and you can submit the form
return true;
}
</script>
感謝所有的支持。
您使用的是日曆庫嗎? – jfriend00 2014-11-02 16:21:03
你應該發佈你的JavaScript。此外'日期'不是有效的輸入類型 – DarkBee 2014-11-02 16:21:12
@DarkBee [與HTML5一起獲取](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input#Attributes)。 – Scimonster 2014-11-02 16:22:15