如何在不重新加载当前页面的情况下加载URL?
问题描述:
我在互联网上看到了一些像这样的工作:
I saw some work around Internet like this:
<a href="./someplace.html"> Link </a>
通常会打开链接或JS未激活:
usually it will be open the link or if JS not active:
http://www.domain.com/someplace.html
但是当JS处于活动状态时,它会像这样打开并将外部页面加载到同一页面而不刷新页面:
but when JS active, it's open like this and load external page into same page without page refreshing:
http://www.domain.com/#/someplace.html
怎么可能?有人可以帮忙吗?
How is it possible? Can someone help?
我先尝试谷歌,也搜索这个网站,但没有找到一个好的答案。
I tried to Google it first, also search this website, but haven't found a good answer.
答
$("a").click(function() {
var $this = $(this),
href = $this.attr("href");
$(document.body).load(href);
location.href = "#" + href;
});
参见 jQuery.fn.load 了解更多详情。