似乎无法找出为什么我的 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) 在你的 fiddle 中包含 jQuery
2) 将提交按钮添加到您的 HTML 中:
<input type="submit" value="Submit" />
3) 在 estimatedTaxesAndFees
消息末尾添加缺少的 '
:
estimatedTaxesAndFees: 'Please enter taxes and fees' // <-- Here
<强> Updated Fiddle
<小时/>您需要将 name
属性添加到您的 input
中才能在此处获取自定义消息:
<input type="text" class="form-control" name="vehiclePrice" id="vehiclePrice"
<input type="text" class="form-control" name="estimatedTaxesAndFees"
<强> Updated Fiddle
关于javascript - jquery.validate 不显示消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21396307/