【问题标题】:How to add header scripts in a php web page?如何在 php 网页中添加标题脚本?
【发布时间】:2017-11-28 03:48:57
【问题描述】:

我有几个使用相同脚本的页面,为此,我想创建一个 header.php 和 footer.php 文件并在每个页面上调用它们,例如。

header.php

<link rel="stylesheet" href="../Framework/bootstrap/css/bootstrap.min.css"/>
<link rel="stylesheet" href="../Framework/bootstrap/css/bootstraptheme.min.css" />

页脚.php

<script src="../Framework/jquery/jquery.min.js"></script>
<script src="../Framework/bootstrap/js/bootstrap.min.js"></script>

还有我的php网页:

 <html>
 <head>
    //add header.php
 </head>
 <body>


  //add footer.php
  </body>
  </html>

【问题讨论】:

标签: javascript php header include footer


【解决方案1】:
<html>
 <head>
    <?php require('header.php'); ?>
 </head>
 <body>


  <?php require('footer.php'); ?>
  </body>
  </html>

正如 chris85 所指出的 - 您可以使用 include 而不是 require...

【讨论】:

    【解决方案2】:
    <html>
     <head>
        <?php include('header.php');?>
     </head>
     <body>
       <?php include('footer.php');?>
     </body>
    </html>
    

    【讨论】:

      【解决方案3】:

      你可以用 jquery as 来实现这个

      <html>
       <head>
          <script src="//code.jquery.com/jquery-1.10.2.js"></script>
          <div id="header"></div> //add header.php
       </head>
       <body>
      
      
        <div id="footer"></div> //add footer.php
        <script>
        $(document).ready(function(){
        $('#header').load('header.html');
        $("#footer").load("footer.html"); 
        });
        </script>
        </body>
        </html>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-12-26
        • 1970-01-01
        • 1970-01-01
        • 2023-03-26
        • 1970-01-01
        • 2016-09-04
        • 1970-01-01
        相关资源
        最近更新 更多