2016-04-30 96 views
1

我想設置設置jquery驗證的自定義信息。我的表單代碼:它總是給msg:「你沒有回答所有必填字段」。但我想改變。jquery驗證信息更改(自定義信息設置)

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

回答

1

請使用data-validation-error-msg="Please enter your first name"代替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>

+0

Vijay完成.. thnx –

+0

這就是偉大@AnshuPratapYadav ...':) '! – vijayP

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> 
+0

馬姆不義和國王.... :) –

+0

什麼錯誤我得到..和請dnt調用mam – shalini

+0

編輯代碼..使用輸入類型並提交和更改腳本標記 – shalini