2012-03-03 65 views
1

我正在使用jQuery.validate插件,但我想更改輸入字段失敗的背景顏色而不是顯示消息?有沒有這樣的插件已經內置或我需要添加一些東西,使其工作?jQuery驗證 - 更改無效元素的css

下面的代碼我到目前爲止:

$("#myForm").validate({ 
    debug: false, 
    rules: { 
     YourName: { 
      required: true, 
     }, 
    }, 
//I want to highlight the failed element here by changing the background color 
    submitHandler: function(form) { 

    $.post('projectform.php', $("#myForm").serialize(), function(data) 
     { 
      $('#myDiv').html(data);  
     }); 
     } 

}); 

回答

3

嘗試設置的自定義功能,如

$("#myForm").validate({ 
      errorPlacement: function(error, element){ 
       element.addClass('errorClass'); 
      }, 
      unhighlight: function(element, errorClass, validClass) { 
       $(element).removeClass('errorClass'); 
      } 
} 

其中errorClass是添加到輸入一個類時,它不是有效