2017-06-24 83 views
-1

我有幾個頁面使用相同的腳本,爲此,我想創建一個header.php和footer.php文件並在每個頁面上調用它們,例如。如何在PHP網頁中添加標題腳本?

的header.php

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

footer.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> 
+0

使用'include'或'require'。 – chris85

+0

[創建PHP頁眉/頁腳]的可能重複(https://stackoverflow.com/questions/8054638/creating-a-php-header-footer) –

回答

0
<html> 
<head> 
    <?php require('header.php'); ?> 
</head> 
<body> 


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

由於chris85指出的 - 你可以使用包括代替的要求......這取決於你想如何在網頁的功能,如果在資源不可用

0

可以作爲

<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> 
使用jQuery實現這一3210
0
<html> 
<head> 
    <?php include('header.php');?> 
</head> 
<body> 
    <?php include('footer.php');?> 
</body> 
</html>