получить значение элемента tr из HTMLTableRowElement - PullRequest
0 голосов
/ 07 апреля 2020

хотел получить значение тега "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(&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>

1 Ответ

0 голосов
/ 07 апреля 2020

Вы не включили все html в вопрос, но я обернул ваш код в table с помощью tbody и произвел поиск по всем элементам tr. После этого вы можете получить доступ к любому свойству с первого tr элемент с getAttribute("key")

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(&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>
...