【发布时间】:2013-07-26 22:37:51
【问题描述】:
基本上,我必须使用 jquery 更改页面的一部分,但鉴于页面的格式,我对选择器链必须是什么感到非常困惑。
<span class="foo1">
<span class="intro"><span class="bar">data I need to change</span></1>
<span>...</span>
<div class="body">This is the only place I can write code on the page</div>
</span>
如何使用 jquery 更改我需要更改的数据?很明显,我没有服务器访问权限。
代码必须以 $(this) 开头,因为 foo 中的 1 总是一个随机数,我猜不出来。该代码必须适用于所有帖子,具体取决于代码所在的帖子。
如果我可以使用普通嵌套,我会的。
代码必须类似于
$(this).sibling('.intro').child('.bar').text('bar');
【问题讨论】:
-
我想更改栏类中的一些文本,但我不知道 jquery 中正确的选择器链来正确选择类栏。
$(this).parent('foo1').child('.intro').child('.bar').text('whatever');不起作用 -
与问题本身无关,但您的 HTML 无效。
div不是span中允许的内容。 -
为什么在 html 中使用
</1> -
我想对您的问题投反对票,但会给您一个机会,请确保在发布问题之前指定每一点:)
-
接受你觉得值得的答案!!!
标签: javascript jquery