我在网上发现了这个代码,可以动态地将HTML页面加载到DIV中:
<script src="http://code.jquery.com/jquery-1.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#page1").click(function(){
$('#result').load('page1.html');
//alert("Thanks for visiting!");
});
$("#page2").click(function(){
$('#result').load('page2.html');
//alert("Thanks for visiting!");
});
});
</script>
但是,我有3个DIV,即标题,导航和内容。我希望导航DIV能够容纳3个链接,即地质,词汇和传奇。当有人点击链接时,我希望替换标题DIV中的内容,而不是导航DIV。这是我的裸代码,减去上面的Internet脚本:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
</head>
<body>
<table id="maintable" width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
<tr style="width:100%; height:20%">
<div id="header">dynamically loaded content, Geological Record onload</div>
</tr>
<tr style="width:100%; height:5%">
<td><div id="navigation">Geological Record | Glossary | Legend</div>
</tr>
<tr style="width:100%; height:75%">
<td><div id="content">MAIN CONTENT HTML PAGE</div></td>
</tr>
</table>
</body>
</html>
答案 0 :(得分:1)
使用元素ID(即导航,内容和标题)代替“#result”。