主导航样式更新:获取网址后进行判断,动态追加class
$(function() {
function navaddclass(n) {
var _clsname = 'active',
_target = '#main-nav';
$(_target + ' a').removeClass(_clsname);
$(_target + ' a:eq("' + n + '")').addClass(_clsname);
}
var _url = location.href;
_url = _url.toLowerCase();
var _nav = new Array();
_nav[1] = ['/index/company1', '/index/company3', '/index/company4'];
_nav[2] = '/product/index';
// _nav[3] = '/project/index/cid/2';
_nav[3] = '/project/index';
_nav[4] = '/article/index';
_nav[5] = ['/video/', '/download/'];
_nav[6] = '/index/company5';
// for (var k in _nav) {
// if(_url.indexOf(_nav[k]) != -1) navaddclass(k);
// }
_nav.forEach(function(v, k) {
if ('string' != typeof(v)) {
for (var k2 in v) {
// console.log(v[k2]);
// console.log(_url.indexOf(v[k2]));
if (_url.indexOf(v[k2]) != -1) {
navaddclass(k);
return false;
}
}
}
if (_url.indexOf(v) != -1) navaddclass(k);
});
})