如何在动态点击TR列中获取TR的第二个TD
how to get second td for tr in dynamic click tr column
如何获取第二个TD文本值。当我单击任何TR列时,必须显示到第二个TD文本值
td:hover{
background-color:red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<table border="1px">
<thead>
<tr>
<th>row1</th><th>row2</th><th>row3</th><th>row4</th><th>row5</th>
</tr>
</thead>
<tbody>
<tr data-class="weeks">
<td class="cls">1</td><td class="cls">2</td><td>3</td><td>4</td><td>5</td>
</tr>
<tr data-class="weeks">
<td>6</td><td>7</td><td>8</td><td>9</td><td>10</td>
</tr>
</tbody>
</table>
$('td').click(function(){//add click event on each td
console.log($(this).closest('tr').find('td:nth-child(2)').text());//log the result of getting the second td text
})
td:hover{
background-color:red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<table border="1px">
<thead>
<tr>
<th>row1</th><th>row2</th><th>row3</th><th>row4</th><th>row5</th>
</tr>
</thead>
<tbody>
<tr data-class="weeks">
<td class="cls">1</td><td class="cls">2</td><td>3</td><td>4</td><td>5</td>
</tr>
<tr data-class="weeks">
<td>6</td><td>7</td><td>8</td><td>9</td><td>10</td>
</tr>
</tbody>
</table>
$(this).closest('tr').find('td:nth-child(2)').text()
- 使用
.closest('tr')
获取点击的 td 的行 - 使用
.find('td:nth-child(2)')
获取单击行的第二个 td - 使用
.text()
获取单击行的第二个 td 的文本
相关文章:
- 在同一tr-jQuery中获取td的值
- 如何从Tr重复的输入文本中获取值
- 在这种情况下,如何获取选定的表tr行
- 获取TR之外最接近的隐藏值
- 如何在点击tr的td后获取tr的id's元素
- 正在获取循环中td元素的tr id
- 获取动态值 tr jquery 的每个 td 值
- 正在获取父<tr>在struts2 jsp页面中使用jquery的表的索引值
- 从 jQuery 中的子元素获取父 tr 元素
- 填充动态表 获取 TR 中的 TD 值
- 如何在动态点击TR列中获取TR的第二个TD
- 获取要在 AJAX 请求中传递的每个 TR 的值
- 单击行中的按钮时获取 HTML TR 的元素
- 在 HTML 表中循环并获取每个 tr 的每个 TD 的值
- 单击时获取TR的所有TD元素
- 使用最接近的.attr获取错误的tr id
- 从选定的tr中获取特定css类的值
- 获取内部输入<tr>在tbody中标记
- 获取作为jQuery对象的tr元素的正确顺序
- 从已检查TR的TD获取参数