gpt4 book ai didi

html - 如何从不同的 HTML 文件中调用 FOOTER 和 NavBar?

转载 作者:太空宇宙 更新时间:2023-11-04 09:49:09 26 4
gpt4 key购买 nike

我正在创建一个简单的网页,其中我希望我的网页的所有静态部分(如 NavBar 和页脚)位于一个单独的 HTML 文件中。

因此,每次我创建一个新页面时,我只需调用它或链接它,以减少我的代码行和加载时间。我怎么能在这里做?请帮助我。

我想做这样的事情:

enter image description here

这是我的代码:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HACMS</title>
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="css/Site.css">
<link rel="stylesheet" type="text/css" href="css/dashboard-navbar.css">
<link rel="stylesheet" type="text/css" href="css/footer-style.css">
<link rel="stylesheet" type="text/css" href="font-awesome/css/font-awesome.min.css" />
<script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="js/csi.min.js"></script>
<script type="text/javascript" src="js/csi.js"></script>
<script type="text/javascript" src="js/bootstrap.js"></script>
<script> $("#includedContent").load("sampleFooter.html"); </script>

</head>
<body>
<h1>THIS IS THE BODY</h1>
<!-- THIS IS MY NAVBAR -->
<nav class="navbar navbar-inverse navbar-fixed-top navbar-custom" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#"><img src="css/images/SSILogo.png" alt="SMESoft Inc." /></a>
</div>
<div class="collapse navbar-collapse navbar-ex1-collapse">

<ul class="nav navbar-nav navbar-right navbar-user">

<li><a href="#" class="hvr-underline-from-center"><i class="fa fa-sign-in" aria-hidden="true"></i>&nbsp;&nbsp;Log Out</a>
</li>
</ul>
</div>
</nav>
<br>
<br>

<!-- THIS IS MY FOOTER -->
<footer>
<div class="footer">
<div class="container">
<div class="row">
<div class="col-lg-5 col-md-4 col-sm-4 col-xs-4">
<h3> Company Background </h3>
<p>
SMESoft Inc. (SSI) is a duly registered company in the Philippines Securities and Exchange Commission (SEC). Established in 2008 and registered in 2011, the company has developed its product line of Business Management Solutions for Small to Medium Enterprise.
Part of the company's expansion is the acquisition of authority to distribute the products and trainings of the internationally renowned RMC Project Management Inc. headquartered in Minnesota, USA. It encompasses product distribution and training conduct with RMC trademark across the country and nearby territories (subject to RMC approval).
Two years ago, SSI started extending an advocacy campaign to raise awareness of the Project Management discipline which the founder believes will benefit the people by applying the necessary skills and concepts for a better future.

</p>
</div>

<div class="col-lg-3 col-md-3 col-sm-4 col-xs-4 ">
<h3> Keep Connected </h3>
<ul class="social">
<li> <a href="#" class="icoFacebook"> <i class=" fa fa-facebook"></i> &nbsp;&nbsp;Like Us on Facebook</a></li>
<li> <a href="#" class="icoInstagram"> <i class="fa fa-instagram"></i> &nbsp;&nbsp;Follow Us on Instagram</a> </li>
<li> <a href="#" class="icoLinkedin"> <i class="fa fa-linkedin"></i> &nbsp;&nbsp;Follow Us on LinkedIn</a></li>
<li> <a href="#" class="icoPinterest"> <i class="fa fa-pinterest"></i> &nbsp;&nbsp;Follow Us on Pinterest</a></li>
<li> <a href="#" class="icoTwitter"> <i class="fa fa-twitter"></i> &nbsp;&nbsp;Follow Us on Twitter</a></li>
</ul>
</div>

<div class="col-lg-4 col-md-3 col-sm-4 col-xs-4">
<h3> Contact Information </h3>
<ul>
<li>
<span class="fa fa-home" aria-hidden="true"></span>
&nbsp;&nbsp;Unit 511-512 VGP Center,
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Legaspi Ayala Avenue,</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Village Makati City </p>
</li>

<li>
<span class="fa fa-mobile" aria-hidden="true"></span>
&nbsp;&nbsp;+63 933.049.8890 (SMART)
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+63 906.297.0995 (GLOBE)</p>
</li>

<li>
<span class="fa fa-phone" aria-hidden="true"></span>
&nbsp;&nbsp;886-9775 | 512-5955
</li>

<li>
<span class="fa fa-envelope-o" aria-hidden="true"></span>
&nbsp;&nbsp;inquire@smesoft.com.ph
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;marketing@smesoft.com.ph</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sales@smesoft.com.ph</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;support@smesoft.com.ph</p>
</li>
</ul>
</div>

</div>
<!--/.row-->
</div>
<!--/.container-->
</div>
<!--/.footer-->

<div class="footer-bottom">
<div class="container">
<center><p>&copy; 2016 SMESoft Inc. All Rights Reserved</p></center>
</div>
</div>
</footer>
</body>
</html>

最佳答案

footer.html/保存在部分文件夹中

Gawa ka ng 部分 na 文件夹。 Doon mo i-save ang footer.html

<footer>This is a footer</footer>

JS(放在想要的页面上)

var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function(){
if (xhttp.readyState == 4 && xhttp.status == 200){
document.body.innerHTML += xhttp.responseText; // you can change the target. As long as you append xhttp.responseText. It will work fine.
}
};
xhttp.open('GET', 'partial/footer.html', true); // note: link the footer.html
xhttp.send();

示例:假设您在 index.html 上

只需将 JS 代码放入您的索引即可。

<body>
<script>
var xhttp = new ....
</script>
</body>

这是没有缓存的基础。如果你想创建路由,你将需要缓存。经过测试。干杯。希望能帮助到你。

关于html - 如何从不同的 HTML 文件中调用 FOOTER 和 NavBar?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39243809/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com