jquery.validate 不显示消息

isa*_*ers 1 javascript jquery

似乎无法找出为什么我的 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)

小提琴

Fel*_*lix 5

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)

更新的小提琴