似乎无法找出为什么我的 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>
Run Code Online (Sandbox Code Playgroud)
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
}
});
});
Run Code Online (Sandbox Code Playgroud)
1) 在你的小提琴中包含 jQuery
2) 将提交按钮添加到您的 HTML 中:
<input type="submit" value="Submit" />
Run Code Online (Sandbox Code Playgroud)
3)'在您的estimatedTaxesAndFees消息末尾添加缺失:
estimatedTaxesAndFees: 'Please enter taxes and fees' // <-- Here
Run Code Online (Sandbox Code Playgroud)
您需要在此处添加name属性input以获取自定义消息:
<input type="text" class="form-control" name="vehiclePrice" id="vehiclePrice"
<input type="text" class="form-control" name="estimatedTaxesAndFees"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17740 次 |
| 最近记录: |