在非常有帮助地指出AJAX和jquery作为对早期问题的回答之后,我发现了很多有用的文档,示例和问题。特别是这......
Replace innerhtml with external page
但是在将我的头撞在砖墙上看似永远的样子之后,我却无法让它发挥作用!希望这对你们来说显而易见!再次,在此先感谢!
这就是我所拥有的......
<head>
<link rel="stylesheet" type="text/css" href="css/new1.css" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(
function navclick(which) {
$('#container').load(which + '.html');
}
)
</script>
</head>
<body id="main">
<div>
<a href="javascript: void(0)" onclick="navclick('page1')">Page 1</a>
<a href="javascript: void(0)" onclick="navclick('page2')">Page 2</a>
</div>
<div id="container">
<p>Placeholder text</p>
</div>
</body>
答案 0 :(得分:0)
我相信应该这样做:
$(function() {
$('.nav').click(function(e) {
e.preventDefault();
var url = $(this).attr("name") + '.html';
$("#container").load(url);
});
});
&#13;
<link rel="stylesheet" type="text/css" href="css/new1.css" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<div>
<a href="#" name="page1" class="nav">Page 1</a>
<a href="#" name="page2" class="nav">Page 2</a>
</div>
<div id="container">
<p>Placeholder text</p>
</div>
&#13;