[英]Include another HTML file in a HTML file - with script execution
我有一部分html代碼在我的每個頁面上重復,我想重用它。
已有一個非常好的鏈接: 在HTML文件中包含另一個HTML文件
我使用jQuery加載html文件(我稱之為模板的單獨的html文件)。
如果那個html文件是靜態的,一切正常。 但是如果我的模板文件包含使用java腳本加載的類(CSS)的元素,那么它就不會被加載。 即使在原始的html文件中,我在head節中引用了正確的css / java腳本。 有任何想法嗎 ?
謝謝,
如果你想將page1.html包含在一個ID為insert-into-me的Div中。 page2.html。
然后使用Jquery這將工作!
<html>
<head>
<script src="jquery.js"></script>
<script>
$(function(){
$("#insert-into-me").load("page1.html");
});
</script>
</head>
<body>
<div id="insert-into-me"></div>
</body>
</html>
使用JSP:
<%@include file="page2.jsp" %>
or
<jsp:include page="..." />
你想要包含在page1中的哪個位置
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.