HTML - 为所有页面使用通用页脚

时间:2016-02-20 06:58:51

标签: jquery html

我想在我网站的所有页面中使用通用页脚。我使用此代码执行此操作:

的index.html:

<html>
<head>
    <script src="js/jquery.min.js"></script>
    <script> 
    $(function(){       
      $("#generalFooter").load("footer.html"); 
    });
    </script>
</head>
<body>
    <div id ="generalFooter"></div>
</body>
</html>

footer.html:

<footer class="footer footer-distributed">
.
.
.
</footer>   

它正在工作,其实我想知道它是在所有页面中调用静态页脚的最佳方式吗?

2 个答案:

答案 0 :(得分:0)

我认为这是包含HTML文件的最佳解决方案。

我尝试了你的代码及其工作。

请检查jQuery文件和footer.html文件的路径。

答案 1 :(得分:0)

https://css-tricks.com/the-simplest-ways-to-handle-html-includes/

使用PHP

PHP提供了一种很棒的方法来使用include()语句解决此问题。通过这种技术,我们可以将所需的任何文件包含在另一个文件中。

    <body>

<!--header start -->
        <?php include("includes/header.php"); ?>
    <!--header end -->

<div clas"container"></div>


<!--footer start -->
    <?php include("includes/footer.php"); ?>
<!--footer end -->

</body>
相关问题