Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用jQuery编辑没有ID或指定类的文本_Javascript_Jquery_Text_Replace - Fatal编程技术网

Javascript 使用jQuery编辑没有ID或指定类的文本

Javascript 使用jQuery编辑没有ID或指定类的文本,javascript,jquery,text,replace,Javascript,Jquery,Text,Replace,我目前正在一个由主机提供的网站上使用javascript,我只能更改网站的指定部分。事实上,我应该能够通过javasript更改所有内容,因为我能够在标题中包含javascript。到目前为止,我已经成功地做到了这一点,但我陷入了无法找到进一步答案的境地,以下是事实: 不可更改的HTML代码如下所示: <div> <intput .... /> <intput .... /> <intput .... /> <intput .

我目前正在一个由主机提供的网站上使用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>

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

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

如果它位于正文内第一个

的旁边:

$('body hr:nth-child(1)').next().html("anything you wana write");
它是
“#somediv”
中的第二个div:

或者是身体里的第五个孩子

$('body:nth-child(5)').html("anything");
或者它是
“#thisdiv”
的父项:


你真正的问题不是很清楚。您是否在询问如何在不影响子元素内容的情况下,将强标记后面的父div的文本作为目标?也许可以与宿主讨论更改其他内容?未启用JavaScript的用户仍将看到旧内容。连接速度慢(或一天中的繁忙时间)的用户将看到旧内容一段时间,然后它将被替换。搜索引擎将无法抓取内容,甚至可能会因为你的这种奇怪行为而惩罚你…@isherwood,是的-这正是我的意思!
$('#somediv div:nth-child(2)').html("Anything you wana write");
$('body:nth-child(5)').html("anything");
$('#thisdiv').parent().append("write anything");