[英]how to load content of one html file into another html file with all its scripts and styles?
我知道这个问题在这里被多次询问并且我已经阅读了这些答案,但我的问题比这更长。 假设有两个文件:a.html和b.html,现在:
a.html包含整个项目中常见的所有脚本和样式以及内容的<div>
标记。
b.html仅包含加载a.html文件的div标记所需的代码。
还有一些仅适用于b.html的其他脚本和样式。
那么,我如何将页面特定的js和css与页面的内容加载到a.html的div中? 以及当我用其自己的js和css文件调用另一个c.html文件的内容时如何删除它们? 任何建议或提示将不胜感激。 谢谢。
使用Jquery Ajax将第2页加载到div中(如下例所示)
第1页(HTML)
<div id="loadepage2here" ></div>
<div id="loadepage3here" ></div>
第1页(js)
$(document).ready(function()
{
$.get('/locationOfPage2.html',function(data){
$("#loadepage3here").empty();
$("#loadepage2here").html(data);
});
$.get('/locationOfPage3.html',function(data){
$("#loadepage2here").empty();
$("#loadepage3here").html(data);
});
});
编辑:询问如何只使用div为多页
第1页(HTML)
<div id="loadepagehere" ></div>
<button onClick="loadPage('page1.html')" >Page 1</button >
<button onClick="loadPage('page2.html')" >Page 2</button >
第1页(js)
loadPage(location)
{
$.get(location,function(data){
$("#loadepagehere").empty();
$("#loadepagehere").html(data);
});
}
您可以使用angular.js来实现此目的。 下面是实现此目的的代码段。
var dynamicHTML = $('#divLoadHTML');
dynamicHTML.load('/Pages/Common/b.html')
$compile(dynamicHTML.contents())($scope);
divHTML是a.html页面上的div。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.