jQuery从URL生成面包屑吗? [英] jQuery generate breadcrumbs from url?
本文介绍了jQuery从URL生成面包屑吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有一种让jQuery从URL在页面上生成面包屑的方法?
Is there a way of getting jQuery to generate breadcrumbs on a page from the url?
因此,如果网站网址为: mysite.com/sec1/sec2/page
So if the site url was: mysite.com/sec1/sec2/page
面包屑类似于: 主页> Sec1> Sec2>页面
The breadcrumbs would be something like: Home > Sec1 > Sec2 > Page
谢谢
推荐答案
这将创建一个可用于生成面包屑的数组.
This will create an array you can use to generate breadcrumbs.
var here = location.href.split('/').slice(3);
var parts = [{ "text": 'Home', "link": '/' }];
for( var i = 0; i < here.length; i++ ) {
var part = here[i];
var text = part.toUpperCase();
var link = '/' + here.slice( 0, i + 1 ).join('/');
parts.push({ "text": text, "link": link });
}
不过,我真的认为您应该在服务器端处理此问题!
Though, I really think you should be handling this at the server side!
这篇关于jQuery从URL生成面包屑吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文