如何使用jquery获取每一行中的数据?

时间:2012-07-24 20:13:46

标签: jquery

我希望连续获取所有值..当用户选择具有class="trSelected"的行时,我会获取行中的每个单元格。

我有类似的东西,但不知道如何获得具有类" trSelected"

的行的值

的jQuery

jQuery(app.rootElement).find('table tr').click(function(event){
    jQuery('.trSelected', this).each( function(){
        var  rowval = $(this).attr('') + $(this).attr('') ..
    });
});

HTML

         <tr class="erow trSelected" style="background-color: yellow;">
       <td align="left" abbr="SEV">
          <div style="text-align: left; width: 40px;"><a class="severity1-img" href="#" title="Critical" alt="Critical">Critical</a></div>
       </td>
       <td align="left" abbr="Verify">
          <div style="text-align: left; width: 140px;"><span title="No">No</span></div>
       </td>
       <td align="left" abbr="Ins">
          <div style="text-align: left; width: 190px;"><span title="lwqun050">lwqun050</span></div>
       </td>
       <td align="right" abbr="Impact">
          <div style="text-align: right; width: 40px;"><span title="1">1</span></div>
       </td>
       <td align="right" abbr="occurrencecount">
          <div style="text-align: right; width: 40px;"><span title="undefined">undefined</span></div>
       </td>
       <td align="left" abbr="NotificationID">
          <div style="text-align: left; width: 100px;"><span title="Host">Host</span></div>
       </td>
       <td align="left" abbr="Owner">
          <div style="text-align: left; width: 100px;"><span title="SYSTEM">SYSTEM</span></div>
       </td>
       <td align="left" abbr="Name">
          <div style="text-align: left; width: 120px;"><span title="Down">undefined</span></div>
       </td>
       <td align="left" abbr="LastNotifiedAt">
          <div style="text-align: left; width: 130px;"><span title="2012-07-23T13:57:11.000-04:00">2012-07-23T13:57:11.000-04:00</span></div>
       </td>
    </tr>

<tr class="erow trSelected" style="background-color: yellow;">
       <td align="left" abbr="SEV">
          <div style="text-align: left; width: 40px;"><a class="severity1-img" href="#" title="Critical" alt="Critical">Critical</a></div>
       </td>
       <td align="left" abbr="Verify">
          <div style="text-align: left; width: 140px;"><span title="No">No</span></div>
       </td>
       <td align="left" abbr="Ins">
          <div style="text-align: left; width: 190px;"><span title="lwqun050">lwqun050</span></div>
       </td>
       <td align="right" abbr="Impact">
          <div style="text-align: right; width: 40px;"><span title="1">1</span></div>
       </td>
       <td align="right" abbr="occurrencecount">
          <div style="text-align: right; width: 40px;"><span title="undefined">undefined</span></div>
       </td>
       <td align="left" abbr="NotificationID">
          <div style="text-align: left; width: 100px;"><span title="Host">Host</span></div>
       </td>
       <td align="left" abbr="Owner">
          <div style="text-align: left; width: 100px;"><span title="SYSTEM">SYSTEM</span></div>
       </td>
       <td align="left" abbr="Name">
          <div style="text-align: left; width: 120px;"><span title="Down">undefined</span></div>
       </td>
       <td align="left" abbr="LastNotifiedAt">
          <div style="text-align: left; width: 130px;"><span title="2012-07-23T13:57:11.000-04:00">2012-07-23T13:57:11.000-04:00</span></div>
       </td>
    </tr>

<tr class="erow " style="background-color: yellow;">
       <td align="left" abbr="SEV">
          <div style="text-align: left; width: 40px;"><a class="severity1-img" href="#" title="Critical" alt="Critical">Critical</a></div>
       </td>
       <td align="left" abbr="Verify">
          <div style="text-align: left; width: 140px;"><span title="No">No</span></div>
       </td>
       <td align="left" abbr="Ins">
          <div style="text-align: left; width: 190px;"><span title="lwqun050">lwqun050</span></div>
       </td>
       <td align="right" abbr="Impact">
          <div style="text-align: right; width: 40px;"><span title="1">1</span></div>
       </td>
       <td align="right" abbr="occurrencecount">
          <div style="text-align: right; width: 40px;"><span title="undefined">undefined</span></div>
       </td>
       <td align="left" abbr="NotificationID">
          <div style="text-align: left; width: 100px;"><span title="Host">Host</span></div>
       </td>
       <td align="left" abbr="Owner">
          <div style="text-align: left; width: 100px;"><span title="SYSTEM">SYSTEM</span></div>
       </td>
       <td align="left" abbr="Name">
          <div style="text-align: left; width: 120px;"><span title="Down">undefined</span></div>
       </td>
       <td align="left" abbr="LastNotifiedAt">
          <div style="text-align: left; width: 130px;"><span title="2012-07-23T13:57:11.000-04:00">2012-07-23T13:57:11.000-04:00</span></div>
       </td>
    </tr>

1 个答案:

答案 0 :(得分:0)

这就是我最终要做的就是返回所选行的值,这是有效的。

它基于trSelected捕获事件并返回行或行中的项及其关联值

谢谢eveyone

jQuery(app.rootElement).find('.flexme1 ').click(function(event){
  console.log(this);
  console.log('Hello Inside  event');
  console.log(event);
      jQuery(this).find('.trSelected').each( function(){
        console.log(this);
          console.log(
              '  Sev: '   + jQuery('td[abbr="Sev"] >div', this).text() +
              '  Ins '   + jQuery('td[abbr="Ins"] >div', this).text() +
              '  Impact: ' + jQuery('td[abbr="Impact"] >div span', this).text()
          );
      });
  });