现在假设location.href
为http:/domain.com/en/
。哈希导航URL构造
点击后,我想这是http://domain.com/en/#opened-File.html/1
这样,我知道我需要什么网址,因此,如果一个用户复制和共享此URL我做:
$(document).ready(function(){
var info = window.location.hash.match(/^#([^\/]*)\/([^-]*)-(.*)$/),
url="", nivel="", seccion="";
if (info) {
url = info[1];
nivel = info[3];
seccion = info[2];
location.href = url;
}
}
至极工作正常,但我的问题是:
- 这是一个很好的方法吗?
- 这是seo-frendly?
- 你会这样做吗?
这与
$('nav a').each(function(){
if(!$(this).hasClass('enlaceAnulado')){
/*Recopilamos*/
var href = $(this).attr('href');
var id = $(this).attr('id');
var parts = id.split("_");
var seccion = parts[0];
var nivel = parseInt(parts[1])+1;
/*Quitamos el enlace*/
$(this).attr('href','javascript:void(0)');
/*Guardamos la información.*/
$(this).data('hrefnot',href);
$(this).data('nivel',nivel);
$(this).data('seccion',seccion);
$(this).addClass('enlaceAnulado');
}
});
所以链接一起工作,其中静态的,但是我这样做是为了提高通过AJAX用户体验,并加载内容
我建议编辑您的帖子。其中,我添加了一个缺少的'}'。由于代码“工作正常”,我在发布问题时假定这个错字处于隐藏状态。如果情况并非如此,请恢复编辑。 – PPvG 2011-12-28 15:30:26
是这样,谢谢!!!! – 2011-12-28 15:37:06