背景:我有一个带有如下标记的页面。我正在使用 jQuery 的 .load() 方法将 div.content-container 的内容替换为以下代码:
$(document).on('click', 'button#page2', function() {
$("div.content-container").load("page2.html");
});
问题:该方法有效,但我想在 URL 后面加上一个哈希,即 #page2,这将允许后退按钮功能。有没有办法将此功能添加到完全基于 HTML 和 jQuery 的站点.load()
?
我看过 Ben Alman 的 BBQ 插件,但作为异步内容的新手和 jQuery 的非专家,我无法弄清楚如何在我的项目中实现它。
主页的HTML:
<head>
<!--scripts & styles-->
</head>
<body>
<button id="page2">Page 2</button>
<button id="page3">Page 3</button>
<div class="content-container">
<!--content is loaded here-->
</div>
</body>
page2.html(和以后的页面)不是完整的 HTML 文档:
<p>Here's some content from the second page.</p>