Jquery验证消息更改(自定义消息集)

时间:2016-04-30 06:36:31

标签: javascript php jquery validation webpage

我想设置jquery验证的自定义msg。我的表单代码:它总是给msg:"你没有回答所有必填字段"。但我想改变。

<form id="addproductform" method="post" action="" role="form">
    <div class="col-md-6">
        <div class="form-group">
            <label>Name </label>
            <input data-validation="required" data-msg="Please enter your first name" class="form-control" placeholder="Enter name">
        </div>
</form>

Jquery的: -

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery-form-validator/2.2.8/jquery.form-validator.min.js"></script>
<script>
    $.validate({
        decimalSeparator: ','
    });
</script>

2 个答案:

答案 0 :(得分:1)

    <script src="//code.jquery.com/jquery-1.9.1.js"></script>
    <script src="//ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js"></script>

      <form id="addproductform"  method="post" action="" role="form">
                        <div class="col-md-6">
                            <div class="form-group">
                                <label>Name </label>
                                <input name="name" class="form-control"    placeholder="Enter name"  >
  <input type="submit">
                            </div>
     </form>

     <!-- jQuery Form Validation code -->

       <script>

    // When the browser is ready...
    $(function() {

    // Setup form validation on the #register-form element
    $("#addproductform").validate({

        // Specify the validation rules
        rules: {
            name: "required",
                    },

        // Specify the validation error messages
        messages: {
            name: "Please enter your name",

        },

        submitHandler: function(form) {
            form.submit();
        }
    });
     });
    </script>

答案 1 :(得分:1)

请使用data-msg="Please..."代替$.validate({ decimalSeparator: ',' });,如下所示:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery-form-validator/2.2.8/jquery.form-validator.min.js"></script>
<form id="addproductform" method="post" action="" role="form">
    <div class="col-md-6">
        <div class="form-group">
            <label>Name </label>
            <input data-validation="required" data-validation-error-msg="Please enter your first name" class="form-control" placeholder="Enter name">
        </div>
      <input type="submit" value="Submit" />
</form>
var destinationPdf = new PdfDocument(destinationFilePath);
Int32 count = destinationPdf.PageCount;