[英]Clear jquery.validate error messages on change/hide of disabled attributes
[英]jquery.validate not showing messages
似乎無法找出為什么我的jquery.validate腳本未顯示消息。 有人看到我在做什么錯嗎?
嘗試在單獨的div中顯示消息:
的HTML:
<form class="cmxform" id="commentForm" method="get" action="">
<label for="vehiclePrice" class="form-control-label vpl">Vehicle Price</label>
<input type="text" class="form-control" id="vehiclePrice" placeholder="$0" onkeypress="return isNumberKey(event)" value="25592" required />
<label for="estimatedTaxesAndFees" class="form-control-label etfl">Estimated Taxes and Fees</label>
<input type="text" class="form-control" id="estimatedTaxesAndFees" placeholder="$0" onkeypress="return isNumberKey(event)" value="2843" required />
</form>
<div id="error-note"></div>
js:
$(document).ready(function() {
$('#commentForm').validate({
errorLabelContainer: "#error-note",
wrapper: "li",
onfocusout: function(element, event) {
this.element(element);
},
rules: {
vehiclePrice: 'required',
estimatedTaxesAndFees: 'required'
},
messages: {
vehiclePrice: 'Please enter vehicle price',
estimatedTaxesAndFees: 'Please enter taxes and fees
}
});
});
1)在您的小提琴中包含jQuery
2)在您的HTML中添加提交按鈕:
<input type="submit" value="Submit" />
3)在estimatedTaxesAndFees
消息的末尾添加缺少的'
:
estimatedTaxesAndFees: 'Please enter taxes and fees' // <-- Here
您需要在input
添加name
屬性,才能在此處獲取自定義消息:
<input type="text" class="form-control" name="vehiclePrice" id="vehiclePrice"
<input type="text" class="form-control" name="estimatedTaxesAndFees"
你有一個未封閉的字符串文字,同樣在小提琴中不包括jQuery
$(document).ready(function() {
$('#commentForm').validate({
errorLabelContainer: "#error-note",
wrapper: "li",
onfocusout: function(element, event) {
this.element(element);
},
rules: {
vehiclePrice: 'required',
estimatedTaxesAndFees: 'required'
},
messages: {
vehiclePrice: 'Please enter vehicle price',
estimatedTaxesAndFees: 'Please enter taxes and fees'//closing ' was missing
}
});
});
演示: 小提琴
如果您清除文本框的內容/或在表單中添加提交按鈕/或手動調用表單的valid()
方法,則驗證將觸發
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.