错误还是我的愚蠢
不确定我是否错过了一些东西,但这不起作用:
$(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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
.children
的选择器参数是一个过滤器。$(this).children('td.threadtitle a')
查找与选择器td.threadtitle a
匹配的节点 和 为this
的直接子级。假设您的 threadtitletd
位于this
内部,并且不高于或等于它,则这种情况永远不会发生。我认为您可能真正需要的是一个上下文选择器:
它会找到与该选择器匹配的内容,只要它们出现在
this
下的任何位置。The selector argument to
.children
is a filter.$(this).children('td.threadtitle a')
finds nodes which match the selectortd.threadtitle a
and are direct children ofthis
. Assuming that your threadtitletd
s are inside ofthis
, 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:
which finds things that match that selector as long as they occur anywhere under
this
.子级
,则应该使用“td.threadtitle > a”
。否则它应该是find('a')
。children
, you should use"td.threadtitle > a"
. Otherwhise it should befind('a')
.