jquery循环遍历表进行文本比较

发布于 2024-12-06 17:21:54 字数 715 浏览 1 评论 0原文

循环遍历表不是问题。

循环遍历表并同时进行比较,为同一行中的另一个 td 分配不同的值是一个问题。这怎么办???

- going through #tblView tbody tr.class

        - to find through all row for second td and see whether the .text() is "completed"
                - if yes
                        - then third td's span's inner text set to "bingo"
                - else
                        - do nothing
                - end


<table id="tblView">

<tbody>

<tr class="class">

<td>completed</td>
<td></td>
<td></td>

</tr>

<tr class="class">

<td>not yet</td>
<td></td>
<td></td>

</tr>

</tbody>

</table>

Looping through the table is not a problem.

Looping through the table and do comparison at the same time assigning the other td in same row with different value is a problem. How can this be done ???

- going through #tblView tbody tr.class

        - to find through all row for second td and see whether the .text() is "completed"
                - if yes
                        - then third td's span's inner text set to "bingo"
                - else
                        - do nothing
                - end


<table id="tblView">

<tbody>

<tr class="class">

<td>completed</td>
<td></td>
<td></td>

</tr>

<tr class="class">

<td>not yet</td>
<td></td>
<td></td>

</tr>

</tbody>

</table>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你是我的挚爱i 2024-12-13 17:21:54

尝试 -

$("#tblView tbody tr.class").each(function() {
    if ($(this).find("td:eq(1)").text() === "completed") $(this).find("td:eq(2)").text('bingo'); 
}) 

演示 - http://jsfiddle.net/d45ZQ/1/

Try -

$("#tblView tbody tr.class").each(function() {
    if ($(this).find("td:eq(1)").text() === "completed") $(this).find("td:eq(2)").text('bingo'); 
}) 

Demo - http://jsfiddle.net/d45ZQ/1/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文