考虑以下代码段:
<div id="help"></div>
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script>
var loadPage = function (){
$("#help").load("http://localhost:3000/manual.html");
}
onload=loadPage;
</script>
这存在于我的主页上:
http://localhost:3000/
上面的代码可以正常工作并加载我的手册页。但是,如果我在manual.html中单击这样的链接:
<a href='#introduction'>Introduction</a>
然后,帮助div中的页面跳转到#introduction部分,但是我的浏览器中的网址更新为:
http://localhost:3000/#introduction
这是没有意义的,因为#introduction锚仅存在于manual.html中,如何防止#help div中的链接影响浏览器中的地址栏?
试试这个
$('a').click(function(e) {
e.preventDefault();
$("#help").load($(this).attr('href'));
})
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句