错误还是我的愚蠢

发布于 2024-08-04 19:19:31 字数 257 浏览 1 评论 0原文

不确定我是否错过了一些东西,但这不起作用:

$(this).children('td.threadtitle a').html('thread title');

但是,

$(this).children('td.threadtitle').children('a').html('thread title');

我只是想了解为什么会发生这种情况。但这是一个错误吗?

Not sure if I've just missed something but this doesn't work:

$(this).children('td.threadtitle a').html('thread title');

However this does

$(this).children('td.threadtitle').children('a').html('thread title');

I'm just trying to understand why this is occuring. But is this a bug?

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

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

发布评论

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

评论(2

¢蛋碎的人ぎ生 2024-08-11 19:19:31

.children 的选择器参数是一个过滤器$(this).children('td.threadtitle a') 查找与选择器 td.threadtitle a 匹配的节点 this 的直接子级。假设您的 threadtitle td 位于 this 内部,并且不高于或等于它,则这种情况永远不会发生。

我认为您可能真正需要的是一个上下文选择器:

$('td.threadtitle a', this).html("Thread title")

它会找到与该选择器匹配的内容,只要它们出现在 this 下的任何位置。

The selector argument to .children is a filter. $(this).children('td.threadtitle a') finds nodes which match the selector td.threadtitle a and are direct children of this. Assuming that your threadtitle tds are inside of this, and not above or equal to it, this situation will never happen.

I think that what you might really be looking for is a contextualized selector:

$('td.threadtitle a', this).html("Thread title")

which finds things that match that selector as long as they occur anywhere under this.

我不是你的备胎 2024-08-11 19:19:31
  1. 应该有效。您可以上传一些代码以便我们可以看到您的 html 吗?
  2. 请注意:如果您想要子级,则应该使用“td.threadtitle > a”。否则它应该是find('a')
  1. Should work. Can you upload some code so we can see your html?
  2. Just a note: If you want children, you should use "td.threadtitle > a". Otherwhise it should be find('a').
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文