2015-10-30 50 views
0

我正在使用jquery驗證插件。如何在驗證插件中添加自定義錯誤替換。如何使用jquery驗證插件添加自定義錯誤替換?

<script src="<?php echo base_url(); ?>application/js/jquery.validate.js"> 

</script> 
<script type="text/javascript"> 
    $("#validation-form").validate({ 
     errorPlacement: function(error, element) { 
      $("p.field_validation_error").removeClass("field_validation_error hidden"); 
      error.appendTo('field_validation_error'); 
     }, 
     rules: { 
      old_password: "required", 
      minlength: 2 
     }, 
     messages: { 
      old_password: "Please enter your firstname", 
      minlength: "Your username must consist of at least 2 characters" 
     } 

    }) 
</script> 
<input type="password" name="old_password" id="old_password" autofocus> 
<p class="field_validation_error hidden">Please enter a password...</p> 

如何刪除隱藏類和自定義錯誤replacment jQuery的添加類field_validation_error

回答

0

我發現在你的代碼的一些錯誤停靠jQuery來驗證你的代碼

<script type="text/javascript"> 
    $(document).ready(function() { 
    $("#validation-form").validate({ 

     errorPlacement: function(error, element) { 
      $("p.field_validation_error").removeClass("hidden"); 
      error.appendTo('.field_validation_error'); // You forget . here 
     }, 
     rules: { 
     // this is how you need to define rules 
      "old_password": 
      { 
       required: true, 
       minlength: 2 
      } 
     }, 
     messages: { 
      // and message 
      old_password: 
      { 
       required: "Please enter your firstname", 
       minlength: "Your username must consist of at least 2 characters" 
      } 
     } 

    }); 
    }); 
</script> 
相關問題