Jquery 如何拥有一个完整的ajax导航?
我有个问题 我访问了一个网站:。当我点击一个链接时,地址栏上的链接变为Jquery 如何拥有一个完整的ajax导航?,jquery,ajax,url,navigation,Jquery,Ajax,Url,Navigation,我有个问题 我访问了一个网站:。当我点击一个链接时,地址栏上的链接变为http://currenthiphop.com/#!/+链接。(比如推特、Faceboook……) 但是,在attributehref中没有#。为什么? 是ajax导航,不是吗? 我怎么能做这样的事 谢谢是的。就像在Facebook上一样,它是用javascript制作的。它用于避免使用GET并重新加载页面 $(document).ready(function(){ $('#menu a').each(functio
http://currenthiphop.com/#!/代码>+链接。(比如推特、Faceboook……)
但是,在attributehref
中没有#代码>。为什么?
是ajax导航,不是吗?
我怎么能做这样的事
谢谢是的。就像在Facebook上一样,它是用javascript制作的。它用于避免使用GET并重新加载页面
$(document).ready(function(){
$('#menu a').each(function(){
id = $(this).attr('href');
id = id.substring(id.lastIndexOf('/'));
id = id.substring(0,id.indexOf('.'));
$(this).attr('rel',id);
});
active_page = location.hash.substring(location.hash.lastIndexOf('/')+1)
if (active_page=='')
{
active_page='home'
}
$('#'+active_page).show();
$('#menu a').click(function(e){
e.preventDefault();
$('.content').hide();
$('#'+$(this).attr('rel')).show();
location.hash = '#!/'+$(this).attr('rel');
return false;
-在php页面和JavaScript所在的文件夹中,您有一些图像(1.png、2.png…等)。像Facebook(不久前)一样,如果你复制并粘贴链接,js会检查是否有散列,并将你重定向到想要的图像。代码很旧,不是最好的。这应该让您开始使用
EDIT-jsFiddle实际上没有显示location.hash位。在我的网站上:
.内容{
显示:无;
}
$(文档).ready(函数(){
$('#菜单a')。每个(函数(){
id=$(this.attr('href');
id=id.substring(id.lastIndexOf('/');
id=id.substring(0,id.indexOf('.');
$(this.attr('rel',id);
});
$('#home').show();
$(“#菜单a”)。单击(功能(e){
e、 预防默认值();
$('.content').hide();
$('#'+$(this.attr('rel')).show();
location.hash='#!/'+$(this.attr('rel');
返回false;
});
});
-
-
-
家庭内容。
一个内容。
两个内容。
三个内容。
感谢贾里德·法里什
我有一个小额外的补充,这将允许您在刷新页面后获得活动内容
$(document).ready(function(){
$('#menu a').each(function(){
id = $(this).attr('href');
id = id.substring(id.lastIndexOf('/'));
id = id.substring(0,id.indexOf('.'));
$(this).attr('rel',id);
});
active_page = location.hash.substring(location.hash.lastIndexOf('/')+1)
if (active_page=='')
{
active_page='home'
}
$('#'+active_page).show();
$('#menu a').click(function(e){
e.preventDefault();
$('.content').hide();
$('#'+$(this).attr('rel')).show();
location.hash = '#!/'+$(this).attr('rel');
return false;
因此,它用于避免重新加载页面。伟大的我们怎么能做到这一点?“斯蒂菲-我认为你的问题与此不同,所以你可以考虑打开一个新的问题,询问这类URL修改是否影响SEO。你的页面内链接仍然完好无损,所以我想SEO会有所改进。然而,我不是一个搜索引擎优化专家。此外,这只是一个起点;有很多方法可以实现这一点(例如通过$.get()获取内容),还有一些其他方法可以根据需求和其他考虑因素进行优化。