Question

J'ai étiquette associée à plusieurs callout contrôles, qui devient rouge lorsque l'un est faux.

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

J'essaie cette approche, mais ne sais pas pourquoi élément mainparent enfants ne montre pas la classe 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');        
  }
});

Toute aide sera grandement appréciée.

Était-ce utile?

La solution

Puisque vous venez de la <input> les contrôles de .length doivent être vrai, vous pouvez les supprimer. Vous pouvez raccourcir jusqu'à ce total:

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

Au lieu de .parents('tr:first') vous pouvez utiliser l'équivalent (et moins cher) .closest() , puis trouver des éléments <label> avec attribut for="" et changer la classe sur les

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top