質問

複数のコントロールに関連付けられた吹き出しラベルがあります。いずれかが間違っている場合は赤色になります。

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

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

ご協力をよろしくお願いいたします。

役に立ちましたか?

解決

あなたが来るから から<input>.length 小切手 しなければならない true であるため、削除できます。全体としては次のように短縮できます。

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

の代わりに .parents('tr:first') 同等の(そしてより安価な)ものを使用できます .closest(), を見つけてください。 <label> 要素を持つ for="" 属性を変更し、それらのクラスを変更します。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top