简体   繁体   English

如何从 td 值中获取 ID TR 的值?

[英]How to get the value of an ID TR from td value?

I have this data in a table:我在表中有此数据:

Red
Green
Blue


Yellow
Pink
Orange

I want to show an alert like this:我想显示这样的警报:

alert($(this).closest('tr').find("Orange").text());

But it does not work.但它不起作用。

set an id field for each tr like为每个 tr 设置一个 id 字段

<tr id="1">
<td>Red</td>
<td>Green</td>
<td>Blue</td>
</tr>
<tr id="2">
<td>Yellow</td>
<td>Pink</td>
<td>Orange</td>
</tr>

then alert($(this).closest('tr').attr('id'));然后 alert($(this).closest('tr').attr('id'));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM