在寫頁面的時候,有些東西是一樣的,比如頭部的導航或者尾部的標注。所以復用的東西可以寫到一個文件中,之后再引入,angularjs或是jsp中都有很好的標簽引入,而html沒有,但是可以借助一些方式進行引入。
angularjs文件引入
angularjs 頭部引入
<head> <% include configHead.ejs %> <title>后台管理</title> </head>
angularjs 尾部或中部引入
<% include homeFooter.ejs %>
jsp文件引入
<%@ include file="文件名" %>//(等於是將兩個jsp合並為一個jsp)或 <jsp:include page="文件名">//(相當於將兩個jsp執行后的內容合並成一個頁面)
html文件引入
(1)Js方法 引入homeHeader.html和homeFooter.html,div使用class引入
<script type="text/javascript"> $(document).ready(function () { $('.configHead').load('homeHeader.html'); $('.configFoot').load('homeFooter.html'); }); </script> </head> <body> <header> <div class="configHead">
(2)iframe引入
<iframe name="" frameborder="0" scrolling="no" marginwidth="0" marginheight="0" width="100%" height="170" src="homeFooter.html"></iframe>
(3)css引入
可以在css定義某個class,將所需要添加的東西負載上去,之后引用該class就可以了