查找带有特定文本的 td,然后在该 td 之后立即对其进行操作? [英] Find td with specific text, and operate on the td right after that one?

查看:18
本文介绍了查找带有特定文本的 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 4td,并连接包含在 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天全站免登陆