首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >获取HTMLTableRowElement的tr元素的值

获取HTMLTableRowElement的tr元素的值
EN

Stack Overflow用户
提问于 2020-04-07 18:55:45
回答 1查看 102关注 0票数 0

想要检索"key“标记的值

代码语言:javascript
复制
<tr id="webUIPage_MPD_Downtime_Pareto_Grd_1_0_0000000001" key="DT_002_001" ** parentkey="" class="WebUIGrid_RowClass" level="0" onmouseover="webUIPage_MPD_Downtime_Pareto_Grd_1.rowOnMouseOver(&quot;webUIPage_MPD_Downtime_Pareto_Grd_1&quot;,&quot;webUIPage_MPD_Downtime_Pareto_Grd_1_0_0000000001&quot;)"
  onmouseout="webUIPage_MPD_Downtime_Pareto_Grd_1.rowOnMouseOut(&quot;webUIPage_MPD_Downtime_Pareto_Grd_1&quot;,&quot;webUIPage_MPD_Downtime_Pareto_Grd_1_0_0000000001&quot;)" onclick="webUIPage_MPD_Downtime_Pareto_Grd_1.rowOnClick(&quot;webUIPage_MPD_Downtime_Pareto_Grd_1&quot;,&quot;webUIPage_MPD_Downtime_Pareto_Grd_1_0_0000000001&quot;)"
  style="background-color: rgb(255, 0, 255); color: black;">
  <td class="WebUIGrid_DataCellClass" align="center">
    <div style="background-color:#AFD8F8;color:#AFD8F8;overflow:hidden;width:20px;height:20px;margin:3px;">AFD8F8</div>
  </td>
  <td class="WebUIGrid_DataCellClass" align="left">Machine not running less than 5 minutes</td>
  <td class="WebUIGrid_DataCellClass" align="right">51</td>
  <td class="WebUIGrid_DataCellClass" align="right">41.7min</td>
</tr>

EN

回答 1

Stack Overflow用户

发布于 2020-04-07 21:04:01

您没有在问题中包含所有的html,但是我使用tbody将您的代码包装在table中,并搜索了所有的tr元素。之后,您可以使用getAttribute("key")访问第一个tr元素中的任何属性

代码语言:javascript
复制
var trElements = $('#table-container tbody tr')
const key = trElements[0].getAttribute("key");
console.log(key)
代码语言:javascript
复制
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<table id="table-container">
  <tbody class="tbody-container">
    <tr id="webUIPage_MPD_Downtime_Pareto_Grd_1_0_0000000001" key="DT_002_001" ** parentkey="" class="WebUIGrid_RowClass" level="0" onmouseover="webUIPage_MPD_Downtime_Pareto_Grd_1.rowOnMouseOver(&quot;webUIPage_MPD_Downtime_Pareto_Grd_1&quot;,&quot;webUIPage_MPD_Downtime_Pareto_Grd_1_0_0000000001&quot;)"
      onmouseout="webUIPage_MPD_Downtime_Pareto_Grd_1.rowOnMouseOut(&quot;webUIPage_MPD_Downtime_Pareto_Grd_1&quot;,&quot;webUIPage_MPD_Downtime_Pareto_Grd_1_0_0000000001&quot;)" onclick="webUIPage_MPD_Downtime_Pareto_Grd_1.rowOnClick(&quot;webUIPage_MPD_Downtime_Pareto_Grd_1&quot;,&quot;webUIPage_MPD_Downtime_Pareto_Grd_1_0_0000000001&quot;)"
      style="background-color: rgb(255, 0, 255); color: black;">

      <td class="WebUIGrid_DataCellClass" align="center">
        <div style="background-color:#AFD8F8;color:#AFD8F8;overflow:hidden;width:20px;height:20px;margin:3px;">AFD8F8</div>
      </td>
      <td class="WebUIGrid_DataCellClass" align="left">Machine not running less than 5 minutes</td>
      <td class="WebUIGrid_DataCellClass" align="right">51</td>
      <td class="WebUIGrid_DataCellClass" align="right">41.7min</td>
    </tr>
  </tbody>
</table>

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61078393

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档