想要检索"key“标记的值
<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("webUIPage_MPD_Downtime_Pareto_Grd_1","webUIPage_MPD_Downtime_Pareto_Grd_1_0_0000000001")"
onmouseout="webUIPage_MPD_Downtime_Pareto_Grd_1.rowOnMouseOut("webUIPage_MPD_Downtime_Pareto_Grd_1","webUIPage_MPD_Downtime_Pareto_Grd_1_0_0000000001")" onclick="webUIPage_MPD_Downtime_Pareto_Grd_1.rowOnClick("webUIPage_MPD_Downtime_Pareto_Grd_1","webUIPage_MPD_Downtime_Pareto_Grd_1_0_0000000001")"
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>
发布于 2020-04-07 21:04:01
您没有在问题中包含所有的html,但是我使用tbody将您的代码包装在table中,并搜索了所有的tr元素。之后,您可以使用getAttribute("key")访问第一个tr元素中的任何属性
var trElements = $('#table-container tbody tr')
const key = trElements[0].getAttribute("key");
console.log(key)<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("webUIPage_MPD_Downtime_Pareto_Grd_1","webUIPage_MPD_Downtime_Pareto_Grd_1_0_0000000001")"
onmouseout="webUIPage_MPD_Downtime_Pareto_Grd_1.rowOnMouseOut("webUIPage_MPD_Downtime_Pareto_Grd_1","webUIPage_MPD_Downtime_Pareto_Grd_1_0_0000000001")" onclick="webUIPage_MPD_Downtime_Pareto_Grd_1.rowOnClick("webUIPage_MPD_Downtime_Pareto_Grd_1","webUIPage_MPD_Downtime_Pareto_Grd_1_0_0000000001")"
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>
https://stackoverflow.com/questions/61078393
复制相似问题