javascript - jquery.validate 不显示消息

标签 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>

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
    }
});

});

fiddle

最佳答案

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/

相关文章:

javascript - 有没有办法在以下上下文中伪造 React JS 中的循环动画?

javascript - 当有2个提交值时,如何在javascript中提交表单中的值?

javascript - 仅在特定屏幕尺寸上运行 jquery?

javascript - 如何在 emberjs View 上运行自定义 JavaScript?

javascript - 将 +1 附加到电话号码字段值

javascript - 将字符串转换为数组(不是你想的那样)

javascript - 如何访问 @URL.Action() 中的 javascript 变量

javascript - 反转对象与其他对象事件的耦合方式

javascript - 使用JS在TextArea中加粗字符串

javascript - 如何在基于 TypeScript 的 React Native 应用程序中配置导入的绝对路径?