1

I have callout label associated with multiple controls, which should turn red when either of it is wrong.

<tr>
    <th>
        <asp:Label for="test">jquery will make my class as updnValidationErrorLabel</asp:Label>
    </th>
    <td > this text is right
        <asp:TextBox class='textboxWide taskListCheckPreVital' />
    </td>
    <td>this is wrong text hence it has updnValidationErrorInput
        <asp:TextBox class='dummyclass updnValidationErrorInput'/></td>

</tr>
​

I'm trying this approach, but not sure why mainparent children element does not show with class updnValidationErrorInput

//if my sturcture has updnValidationErrorInput
$('.updnValidationErrorInput').each(function() {
  // go to tr element
  var mainParent = $(this).parents('tr:first');
  // under tr element find updnValidationErrorInput
  if(mainParent.children('.updnValidationErrorInput').length > 0){
  // set label which has for attribute with    updnValidationErrorLabel
  mainParent.children('label').attr('for').removeClass().addClass('updnValidationErrorLabel');        
  }
});

Any help will be greatly appreciated.

4

1 回答 1

0

由于您来自检查必须<input>真实的,因此您可以删除它们。你可以把它缩短到这个整体:.length

$('.updnValidationErrorInput').each(function() {
   $(this).cloesest('tr').find('label[for]')
          .removeClass().addClass('updnValidationErrorLabel');
});

而不是.parents('tr:first')您可以使用等效(并且更便宜).closest(),然后找到任何<label>具有属性的元素for=""并更改它们的类。

于 2010-09-04T01:17:02.113 回答