0

我目前正在一个由主机提供的网站上启动javascript,在该网站上我只能更改网站的指定部分。事实上,我应该能够通过 javasript 更改所有内容,因为我能够在标题中包含 javascript。到目前为止,我已经成功地做到了这一点,但我陷入了无法找到进一步答案的地步,所以这里是事实:

不可更改的HTML代码如下所示:

<div>
  <intput .... />
  <intput .... />
  <intput .... />
  <intput .... />
  <div> ... some unimportant informations ... </div>
  <hr />
  <strong> SOME TEXT: </strong> additional text with important things to change
  <hr />
</div>

问题 :

如何选择我要更改的文本。

我尝试过但没有成功:

$("*").each(function() {
  $("this:contains('important things to change')").replace('important things to change', 'new text here');
}

实现所需的正确方法是什么。

4

1 回答 1

0

有很多方法可以做到这一点,如果你知道那个 div 在哪里,你可以通过以下方式找到它:

'<hr/>'如果它在身体内的第一个旁边:

$('body hr:nth-child(1)').next().html("anything you wana write");

它是内部的第二个 div "#somediv"

$('#somediv div:nth-child(2)').html("Anything you wana write");

或者是里面的第五个孩子body

$('body:nth-child(5)').html("anything");

或其父母"#thisdiv"

$('#thisdiv').parent().append("write anything");
于 2013-03-31T15:58:16.903 回答