【发布时间】:2020-11-26 22:55:17
【问题描述】:
所以我最近才开始做网页设计。 我的 index.html 有一个菜单(包含指向不同页面的链接)。 index.html 页面上的菜单(以非常简化的方式,没有 css 之类的东西)看起来像这样:
<ul>
<li><a class="active" href="index.html"></li>
<li><a href="contactus.html"></li>
<li><a href="help.html"></li>
<ul>
and then there is the content of the page (text, slideshow, images...) - say
<div>
<h1><img><p><script>
</div>
contactus.html 页面如下所示:
<ul>
<li><a href="index.html"></li>
<li><a class="active" href="contactus.html"></li>
<li><a href="help.html"></li>
<ul>
and then there is the content of the page (text, slideshow, images...) - say
<div>
<h1><img2><p><script>
当您单击该链接时,它会将您带到另一个页面。 假设我们有 index.html,我们点击菜单中的一个链接,它会引导我们到 contactus.html。它改变了页面,contactus.html 必须加载。 问题是:是否有可能让contactus.html的内容出现在index.html上(并替换它),但不需要加载另一个页面? 我做了一些研究,发现了一些关于 innerHTML 的东西,但我无法真正理解如何使用它。不久前我开始使用js。 我希望这个问题是有道理的。 非常感谢您的建议和建议。
【问题讨论】:
-
是的,有可能
-
如果我可以问怎么办?
-
这样做(用另一个页面替换索引的全部内容)不会给你任何优势,你正在有效地加载另一个页面。您可能想要的是加载单个内容片段并更新当前页面,这可以通过多种方式完成......从使用 jQuery 进行简单的 ajax 和 dom 操作到使用 Sveltejs、Angular、Vuejs 的完整标记的单页应用程序, React 和其他框架。
-
最简单的方法是使用ajax,但这需要一些php知识。
-
是的,这是可能的,但这并不是很有效。 ReactJs、Angular、VueJs 和类似的东西可以帮助你有效地做到这一点。
标签: javascript html innerhtml