找到具有特定文本的td,然后在该td之后操作? [英] Find td with specific text, and operate on the td right after that one?

查看:158
本文介绍了找到具有特定文本的td,然后在该td之后操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不太熟悉jQuery选择器,所以想要一些帮助。

I'm not very familiar with jQuery selectors, so would like some help.

我有一个这样的表:

<table class="test">
  <tr>
    <td>Section Heading 1</td><td>Section Text 1</td>
  </tr>
  <tr>
    <td>Section Heading 2</td><td>Section Text 2</td>
  </tr>
  <tr>
    <td>Section Heading 3</td><td>Section Text 3</td>
  </tr>
  <tr>
    <td>Section Heading 4</td><td>Section Text 4</td>
  </tr>
  <tr>
    <td>Section Heading 5</td><td>Section Text 5</td>
  </tr>
</table>

我需要做的是找到 td 包含特定文本,并对其右侧的 td 中的文本进行操作。

What I need to do is find the td containing a specific text, and the operate on the text in the td on its right.

说我想找到包含文本 Section Heading 4 td ,并且连接 td 是正确的,文本 hello ,因此 Section Text 4 Section Text 4 hello ..

For example, say I want to find the td containing the text Section Heading 4, and the concatenate the text contained in the td to it's right, with the text hello, so that Section Text 4 becomes Section Text 4 hello ..

哪个jQuery选择器可以用于这个目的?

Which jQuery selector(s) can be used for this purpose ?

推荐答案

我的初步回答漏掉了有关更新文字的问题,下面是一个包含此示例的示例:

My initial answer missed the point about updating the text, here is a sample with this included:

$(".test td:contains(Heading 1)")
    .next().text(function(){
        return $(this).text() + " Hello"
    });

我不相信你可以使用append方法,因为我认为它只适用于添加html标签。

I don't believe you can use the append method as I think it only works to add html tags.

这篇关于找到具有特定文本的td,然后在该td之后操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆