-1

我正在尝试使用 jquery 将类添加到 tr .inside 类名称为 .flexme1 的表中

我尝试了下面的各种选项,但似乎没有用..

  //jQuery("div.flexigrid > table.flexme1 > tr").addClass("cal");

or

        jQuery("div.flexigrid > table.flexme1 > tr").addClass("sev1");
  or 
        jQuery(".erow").addClass("sev2");
   or
        jQuery(".flexigrid > tr").addClass("sev3");
   or
        jQuery(".flexigrid >tr").addClass("sev4");
   or
        jQuery(".flexigrid >tr").addClass("sev5");

我希望 tr 添加 class="somename" 。

<div class="flexigrid">
  ..< some other divs>...<<table> ..</table></div>
... <some other divs>...<table>..</table></div>
---
<div class="bDiv" >
   <table cellspacing="0" cellpadding="0" border="0" class="flexme1" >
      <tbody>
         <tr  class="sev1">
            <td align="left" abbr="InstanceDisplayName8">
               <div style="text-align: left; width: 190px;">undefined</div>
            </td>
            <td align="right" abbr="severity" class="sorted">
               <div style="text-align: right; width: 40px;">&nbsp;</div>
            </td>
            <td align="right" abbr="Impact">
               <div style="text-align: right; width: 40px;">0</div>
            </td>
            <td align="right" abbr="occurrencecount">
               <div style="text-align: right; width: 40px;">undefined</div>
            </td>
            <td align="left" abbr="NotificationID">
               <div style="text-align: left; width: 100px;">Host</div>
            </td>
            <td align="left" abbr="Name">
               <div style="text-align: left; width: 120px;">Down</div>
            </td>
            <td align="right">
               <div style="text-align: right; width: 130px;">undefined</div>
            </td>
         </tr>
         <tr class="erow"  class="sev1">
            <td align="left" abbr="InstanceDisplayName8">
               <div style="text-align: left; width: 190px;">undefined</div>
            </td>
            <td align="right" abbr="severity" class="sorted">
               <div style="text-align: right; width: 40px;">&nbsp;</div>
            </td>
            <td align="right" abbr="Impact">
               <div style="text-align: right; width: 40px;">1</div>
            </td>
            <td align="right" abbr="occurrencecount">
               <div style="text-align: right; width: 40px;">undefined</div>
            </td>
            <td align="left" abbr="NotificationID">
               <div style="text-align: left; width: 100px;">Host</div>
            </td>
            <td align="left" abbr="Name">
               <div style="text-align: left; width: 120px;">Down</div>
            </td>
            <td align="right">
               <div style="text-align: right; width: 130px;">undefined</div>
            </td>
         </tr>
         <tr   class="sev3">
            <td align="left" abbr="InstanceDisplayName8">
               <div style="text-align: left; width: 190px;">undefined</div>
            </td>
            <td align="right" abbr="severity" class="sorted">
               <div style="text-align: right; width: 40px;">&nbsp;</div>
            </td>
            <td align="right" abbr="Impact">
               <div style="text-align: right; width: 40px;">0</div>
            </td>
            <td align="right" abbr="occurrencecount">
               <div style="text-align: right; width: 40px;">undefined</div>
            </td>
            <td align="left" abbr="NotificationID">
               <div style="text-align: left; width: 100px;">Host</div>
            </td>
            <td align="left" abbr="Name">
               <div style="text-align: left; width: 120px;">Down</div>
            </td>
            <td align="right">
               <div style="text-align: right; width: 130px;">undefined</div>
            </td>
         </tr>
         <tr class="erow" >
            <td align="left" abbr="InstanceDisplayName8">
               <div style="text-align: left; width: 190px;">undefined</div>
            </td>
            <td align="right" abbr="severity" class="sorted">
               <div style="text-align: right; width: 40px;">&nbsp;</div>
            </td>
            <td align="right" abbr="Impact">
               <div style="text-align: right; width: 40px;">1</div>
            </td>
            <td align="right" abbr="occurrencecount">
               <div style="text-align: right; width: 40px;">undefined</div>
            </td>
            <td align="left" abbr="NotificationID">
               <div style="text-align: left; width: 100px;">Host</div>
            </td>
            <td align="left" abbr="Name">
               <div style="text-align: left; width: 120px;">BM1M</div>
            </td>
            <td align="right">
               <div style="text-align: right; width: 130px;">undefined</div>
            </td>
         </tr>
         <tr >
            <td align="left" abbr="InstanceDisplayName8">
               <div style="text-align: left; width: 190px;">undefined</div>
            </td>
            <td align="right" abbr="severity" class="sorted">
               <div style="text-align: right; width: 40px;">&nbsp;</div>
            </td>
            <td align="right" abbr="Impact">
               <div style="text-align: right; width: 40px;">0</div>
            </td>
            <td align="right" abbr="occurrencecount">
               <div style="text-align: right; width: 40px;">undefined</div>
            </td>
            <td align="left" abbr="NotificationID">
               <div style="text-align: left; width: 100px;">Host</div>
            </td>
            <td align="left" abbr="Name">
               <div style="text-align: left; width: 120px;">Down</div>
            </td>
            <td align="right">
               <div style="text-align: right; width: 130px;">undefined</div>
            </td>
         </tr>
         <tr class="erow" >
            <td align="left" abbr="InstanceDisplayName8">
               <div style="text-align: left; width: 190px;">undefined</div>
            </td>
            <td align="right" abbr="severity" class="sorted">
               <div style="text-align: right; width: 40px;">&nbsp;</div>
            </td>
            <td align="right" abbr="Impact">
               <div style="text-align: right; width: 40px;">4</div>
            </td>
            <td align="right" abbr="occurrencecount">
               <div style="text-align: right; width: 40px;">undefined</div>
            </td>
            <td align="left" abbr="NotificationID">
               <div style="text-align: left; width: 100px;">Host</div>
            </td>
            <td align="left" abbr="Name">
               <div style="text-align: left; width: 120px;">BM1N</div>
            </td>
            <td align="right">
               <div style="text-align: right; width: 130px;">undefined</div>
            </td>
         </tr>
         <tr >
            <td align="left" abbr="InstanceDisplayName8">
               <div style="text-align: left; width: 190px;">undefined</div>
            </td>
            <td align="right" abbr="severity" class="sorted">
               <div style="text-align: right; width: 40px;">&nbsp;</div>
            </td>
            <td align="right" abbr="Impact">
               <div style="text-align: right; width: 40px;">0</div>
            </td>
            <td align="right" abbr="occurrencecount">
               <div style="text-align: right; width: 40px;">undefined</div>
            </td>
            <td align="left" abbr="NotificationID">
               <div style="text-align: left; width: 100px;">Host</div>
            </td>
            <td align="left" abbr="Name">
               <div style="text-align: left; width: 120px;">Down</div>
            </td>
            <td align="right">
               <div style="text-align: right; width: 130px;">undefined</div>
            </td>
         </tr>
         <tr class="erow" >
            <td align="left" abbr="InstanceDisplayName8">
               <div style="text-align: left; width: 190px;">undefined</div>
            </td>
            <td align="right" abbr="severity" class="sorted">
               <div style="text-align: right; width: 40px;">&nbsp;</div>
            </td>
            <td align="right" abbr="Impact">
               <div style="text-align: right; width: 40px;">0</div>
            </td>
            <td align="right" abbr="occurrencecount">
               <div style="text-align: right; width: 40px;">undefined</div>
            </td>
            <td align="left" abbr="NotificationID">
               <div style="text-align: left; width: 100px;">Host</div>
            </td>
            <td align="left" abbr="Name">
               <div style="text-align: left; width: 120px;">Down</div>
            </td>
            <td align="right">
               <div style="text-align: right; width: 130px;">undefined</div>
            </td>
         </tr>
         <tr >
            <td align="left" abbr="InstanceDisplayName8">
               <div style="text-align: left; width: 190px;">undefined</div>
            </td>
            <td align="right" abbr="severity" class="sorted">
               <div style="text-align: right; width: 40px;">&nbsp;</div>
            </td>
            <td align="right" abbr="Impact">
               <div style="text-align: right; width: 40px;">0</div>
            </td>
            <td align="right" abbr="occurrencecount">
               <div style="text-align: right; width: 40px;">undefined</div>
            </td>
            <td align="left" abbr="NotificationID">
               <div style="text-align: left; width: 100px;">Host</div>
            </td>
            <td align="left" abbr="Name">
               <div style="text-align: left; width: 120px;">Down</div>
            </td>
            <td align="right">
               <div style="text-align: right; width: 130px;">undefined</div>
            </td>
         </tr>
         <tr class="erow" >
            <td align="left" abbr="InstanceDisplayName8">
               <div style="text-align: left; width: 190px;">undefined</div>
            </td>
            <td align="right" abbr="severity" class="sorted">
               <div style="text-align: right; width: 40px;">&nbsp;</div>
            </td>
            <td align="right" abbr="Impact">
               <div style="text-align: right; width: 40px;">0</div>
            </td>
            <td align="right" abbr="occurrencecount">
               <div style="text-align: right; width: 40px;">undefined</div>
            </td>
            <td align="left" abbr="NotificationID">
               <div style="text-align: left; width: 100px;">Host</div>
            </td>
            <td align="left" abbr="Name">
               <div style="text-align: left; width: 120px;">Down</div>
            </td>
            <td align="right">
               <div style="text-align: right; width: 130px;">undefined</div>
            </td>
         </tr>
      </tbody>
   </table>
   <div class="iDiv" style="display: none;"></div>
</div>


</div><!-- end of div>
4

2 回答 2

1

这样做: -

jQuery(".bDiv table.flexme1 tr").addClass("inside");

参考现场演示

于 2012-07-24T14:19:26.663 回答
1

你几乎是对的,只需删除>- 这table不是他们之间的直接孩子.flexigriddiv.bDiv

jQuery("div.flexigrid table.flexme1 tr").addClass("somename");
于 2012-07-24T14:14:52.130 回答