开发者

Jquery Validate Plugin: Highlight/Unhightlight First Error Only

I have a form which is laid out inside a table. I am looking for a way to change the background colour of the first table row that contains an error.

Is there a way to target the first error message element when using Hightligh and Unhighlight. The actual DOM part I understand, but I cant seem to find any method of stopping it after the first error

  highlight: function(element, errorClass, validClass) {
      // Someway of only applying the following style to the first error message
      // ??????????
         $(element).parent("td").parent("tr").css({
             'border':'1px solid #c00',
             'background':'#fff0f0'
             });
        },
 unhighlight: fu开发者_StackOverflownction(element, errorClass, validClass) {
         $(element).parent("td").parent("tr").css({
             'border':'1px solid #ccc',
             'background':'#fff'
             });


You could do something like this:

onfocusin: function (element) {
    // remember the last active field
    this.lastActive = element;
},
highlight: function (element, errorClass, validClass) {  
    // highlight only the last active
    if (this.lastActive && (this.lastActive == element))
        $(element).parent("td").parent("tr").css({
             'border':'1px solid #c00',
             'background':'#fff0f0'
             });   
}

Not sure what you mean by first.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜