Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/89.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在同一HTML文件中重复早期文本_Javascript_Html - Fatal编程技术网

如何使用Javascript在同一HTML文件中重复早期文本

如何使用Javascript在同一HTML文件中重复早期文本,javascript,html,Javascript,Html,我希望在我的网站上为我的文章创建一个新页面,在页面后面复制我的标签的内容 我想包含一小段代码(我想象的是Javascript,但其他东西也可以),在底部动态添加我文章的标题,使其看起来像这样: If you enjoyed reading <span id="populate"></span> 这是本文的标题 然后在页面的末尾: 相关文章: 如果你喜欢阅读 ... 填充“这是文章的标题” 那么,为什么不探讨以下类似的文章呢 我已经研究过了,除了复制标记外,似乎看不

我希望在我的网站上为我的文章创建一个新页面,在页面后面复制我的
标签的内容

我想包含一小段代码(我想象的是Javascript,但其他东西也可以),在底部动态添加我文章的标题
,使其看起来像这样:

If you enjoyed reading <span id="populate"></span>

这是本文的标题
然后在页面的末尾:
相关文章:
如果你喜欢阅读
... 填充“这是文章的标题”
那么,为什么不探讨以下类似的文章呢


我已经研究过了,除了复制
标记外,似乎看不到更多的方法。这可能真的很简单,但有人知道怎么做吗?

HTML

<h1 id="something"> title </h1>
<h1 id="repeated_title"></h1>
HTML


如果您有这样的代码:

If you enjoyed reading <span id="populate"></span>

如果您有这样的代码:

If you enjoyed reading <span id="populate"></span>

有很多方法可以做到这一点,javascript并不是最好的方法,因为您应该在服务器端这样做

<h1 id='title'> This is the title of the article </h1>

and then at the end of the page:

Related Articles:

<p> If you enjoyed reading <span id="title2"></span> then why not explore the following similar articles? [/p]
<script>$("#title2").text(#("#title").text);</script>
这是本文的标题
然后在页面的末尾:
相关文章:
如果你喜欢阅读,那么为什么不浏览以下类似的文章呢?[p]
$(“#title2”).text(#(“#title”).text);

有很多方法可以做到这一点,而javascript并不是最好的方法,因为您应该在服务器端这样做

<h1 id='title'> This is the title of the article </h1>

and then at the end of the page:

Related Articles:

<p> If you enjoyed reading <span id="title2"></span> then why not explore the following similar articles? [/p]
<script>$("#title2").text(#("#title").text);</script>
这是本文的标题
然后在页面的末尾:
相关文章:
如果你喜欢阅读,那么为什么不浏览以下类似的文章呢?[p]
$(“#title2”).text(#(“#title”).text);

在生成/写入HTML时而不是在运行时复制数据可能是一个更好的主意,但如果不可能,请将要复制文本的位置包装到可以引用的元素中,例如通过id:

<span id="title_copy"></span>

在生成/写入HTML时而不是在运行时复制数据可能是一个更好的主意,但如果不可能,请将要复制文本的位置包装到可以引用的元素中,例如通过id:

<span id="title_copy"></span>

在纯Javascript中,这就是您要做的(看,没有jQuery)

标题
如果你喜欢阅读
Javascript

<script>
    document.getElementById("populate").innerHTML = document.getElementById("something").innerHTML;
</script>

document.getElementById(“填充”).innerHTML=document.getElementById(“某物”).innerHTML;
不过最好还是在服务器端完成


另外,您不必将
标签放在那里。文档中的任何地方都可以,而且主要是在纯Javascript中的
中完成的,这就是您要做的(看,没有jQuery)

标题
如果你喜欢阅读
Javascript

<script>
    document.getElementById("populate").innerHTML = document.getElementById("something").innerHTML;
</script>

document.getElementById(“填充”).innerHTML=document.getElementById(“某物”).innerHTML;
不过最好还是在服务器端完成

另外,您不必将
标签放在那里。文档中的任何地方都可以,而且大部分都是在

<script>
    document.getElementById("populate").innerHTML = document.getElementById("something").innerHTML;
</script>