1、Html中引入Html文件:
在論壇中經常有網友問到,能夠在一個html的文件當中讀取另外一個html文件的內容嗎?結果是肯定的,並且方法不僅一種,在之前我只會使用iframe來引用,後來發現了另外的幾種方法,那今天就總結這幾種方法讓你們參考一下。php
1.IFrame引入,看看下面的代碼css
<iframe src="file.html" width="100%" height="500" marginheight="0" marginwidth="0" frameborder="0" scrolling="no"></iframe>
src:文件引入相對路徑,也能夠是一個絕對路徑的網址等;
frameborder:引入的文件邊框寬度爲0;
scrolling:不使用滾動條的形式;html
可參考網站1:http://www.ccvita.com/376.htmljquery
可參考網站2: http://fity.cn/post/423/post
2.<object>方式引入網站
<object style="border:0px" type="text/x-scriptlet" data="file.html" width=100% height=30></object>
width、height、border:可按需求設定ui
3.Behavior的download方式url
<span id=showImport></span> <IE:Download ID="oDownload" STYLE="behavior:url(#default#download)" /> <script> function onDownloadDone(downDate){ showImport.innerHTML=downDate } oDownload.startDownload('file.html',onDownloadDone) ; </script>
此方法按理說是比較嚴謹的,但代碼過於繁瑣,網上有一部分人說建議此方法,本人spa
4.JQ的onload方法
/*導入頁面*/ code
$(document).ready(function(){ $(".top").load("top.html"); $(".footer").load("footer.html"); }); top.html和footer.html文件建議寫本身的css和js,以避免出現沒必要要的錯誤
把他寫入到js文件裏,在須要的頁面導入就能夠了,記得引入jquery.js文件。
2、Php中引入Php文件
1.include()
include()語句將在其被調用的位置處包含一個文件。
eg: include("init.php");
2.include_once() - 建議使用
include_once()首先驗證是否已經包含了該文件,若是已經包含,則再也不執行include_once();
eg: include_once("init.php");
3.require()
與include()同樣,不過要放在php程序最前面;
4.require_once()
與include_once()同樣,不過要放在php程序最前面;
區別:require一個文件出現錯誤的話,程序終止執行,顯示致命錯誤 include一個文件出現錯誤的話,程序不會終止執行,顯示警告錯誤