简体   繁体   English

有没有办法加载带有静态页眉和页脚的页面,但更改内容正文

[英]Is there a way to load a page with static header and footer, yet changing content body

I need to make a webpage where the main.html loads a page with a header and footer that will remain steady after I click on some navigation links, but only changing the body content, all this, using Javascript.我需要制作一个网页,其中 main.html 加载一个带有页眉和页脚的页面,在我点击一些导航链接后将保持稳定,但只更改正文内容,所有这些,使用 Javascript。 The body content comes from another html document in the same folder.正文内容来自同一文件夹中的另一个 html 文档。 I've seen some answers to this, but very old ones using PHP.我已经看到了一些答案,但是使用 PHP 的很旧。 Please help.请帮忙。

BTW, I'm not using server yet, only loading from file with Chrome.顺便说一句,我还没有使用服务器,只使用 Chrome 从文件加载。 Basically I want to replace the whole body of the page with the body of another html.基本上我想用另一个 html 的正文替换页面的整个正文。

You can change part of a website by javascript and load content from other urls using ajax.您可以通过 javascript 更改网站的一部分,并使用 ajax 从其他 url 加载内容。

https://www.w3schools.com/js/js_ajax_intro.asp https://www.w3schools.com/js/js_ajax_intro.asp

And you can use jQuery lib to perform the ajax calls:您可以使用 jQuery lib 来执行 ajax 调用:

https://www.w3schools.com/jquery/jquery_ref_ajax.asp https://www.w3schools.com/jquery/jquery_ref_ajax.asp

The ajax calls can be to a server (this includes firebird and other content from the cloud) or to some files of yours. ajax 调用可以是服务器(包括来自云的 firebird 和其他内容)或您的某些文件。

It's not the only way, you could also have a look at iframes to see whether they fit your needs.这不是唯一的方法,您还可以查看 iframe 以查看它们是否符合您的需求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM