[英]jquery.validate not showing messages
Can't seem to find out why my jquery.validate script is not showing the messages. 似乎无法找出为什么我的jquery.validate脚本未显示消息。 Anyone see what I am doing wrong?
有人看到我在做什么错吗?
Trying to display messages in a separate div: 尝试在单独的div中显示消息:
html: 的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: 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) Include jQuery in your fiddle 1)在您的小提琴中包含jQuery
2) Add submit button to your HTML: 2)在您的HTML中添加提交按钮:
<input type="submit" value="Submit" />
3) Add missing '
at the end of your estimatedTaxesAndFees
message: 3)在
estimatedTaxesAndFees
消息的末尾添加缺少的'
:
estimatedTaxesAndFees: 'Please enter taxes and fees' // <-- Here
You need to add name
attribute to your input
to get custom message here: 您需要在
input
添加name
属性,才能在此处获取自定义消息:
<input type="text" class="form-control" name="vehiclePrice" id="vehiclePrice"
<input type="text" class="form-control" name="estimatedTaxesAndFees"
you had a unclosed string literal, also in the fiddle jQuery was not included 你有一个未封闭的字符串文字,同样在小提琴中不包括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
}
});
});
The validation will trigger if you clear the contents of a textbox/or you add a submit button to the form/or call the valid()
method of the form manually 如果您清除文本框的内容/或在表单中添加提交按钮/或手动调用表单的
valid()
方法,则验证将触发
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.