-1

我正在尝试使用 jquery 向 tr 添加类。

我尝试了各种选项,但似乎没有用。任何帮助将不胜感激。ñ

  //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="sev" 。

<div class="flexigrid">
  ..< some other divs>
... <some other divs>
---
<div class="bDiv" style="height: 200px;">
   <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 flexidiv>
4

2 回答 2

0

您没有 div 与 class flexigrid。你有div.bDiv

二、表格行有错误:

class="flexme1 stype=&quot;display: none&quot;"

它应该是:

class="flexme1" style="display: none"

第三,您有多个带有id="rowHost". 元素必须具有唯一 ID。

于 2012-07-23T21:03:41.247 回答
0

首先,您的代码中没有 div 具有“flexigrid”类,因此 jquery 不会找到您想要的内容。

现在,这应该工作

$("bDiv tr").addClass("sev1");
于 2012-07-23T21:05:59.723 回答