1

複数のコントロールに関連付けられたコールアウトラベルがあり、どちらかが間違っていると赤に変わるはずです。

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

私はこのアプローチを試していますが、主な親の子要素がクラスで表示されない理由がわかりません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');        
  }
});

どんな助けでも大歓迎です。

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 に答える