我已经编写了这段代码来切换我的html内容:
$.get( "header.html", function( data ) {
$( "#header-import" ).html( data );
alert( "Load was performed." );
});
$.get( "navigation.html", function( data ) {
$( "#navigation-import" ).html( data );
alert( "Load was performed." );
});
$.get( "home.html", function( data ) {
$( "#content-import" ).html( data );
alert( "Load was performed." );
});
好像导入的JS脚本没有正确加载。 我想我必须在加载页面后“重新加载”我的主html文件中的部分。任何想法家伙?我尝试了一些东西,但它没有用。
答案 0 :(得分:1)
使用.ajax()并拥有dataType,可以产生完美的工作结果:
<html>
<head>
<script src="jquery-1.10.2.js"></script>
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery.ajax({
url : "test1.html",
dataType: "html",
success : function (data) {
jQuery( "#header" ).html( data );
console.log("a: "+data);
//alert( "Load was performed." );
}
});
jQuery.ajax({
url : "test2.html",
dataType: "html",
success : function (data) {
jQuery( "#navigation" ).html( data );
console.log("b: "+data);
//alert( "Load was performed." );
}
});
});
</script>
</head>
<body>
<h1>TEST</h1>
<div id="header">
</div>
<div id="navigation">
</div>
</body>
</html>