后台的同事因为把nav公用了,所以无法单页添加active,一下方法通过判断url的后缀给当前页添加active

	$(function(){
var _nava= $('.nav .nav-wrapper a');
var _url = window.location.href;
var _host = window.location.host;
for(var i = 0; i<_nava.length ; i++){
var _astr = _nava.eq(i).attr('href');
if(_url.indexOf(_astr) != -1){
_nava.eq(i).addClass('active').siblings().removeClass('active');
}else if(_url == ('http://'+_host+'/')){
_nava.eq(0).addClass('active').siblings().removeClass('active');
}
}
})

由于后台同事,类别分配不同往常;在点击一个导航进入后,可以正常运行,但是当点击某一条信息进入后,由于网址又是一个新的html,并没有包括在原来的类别内,之后通过网站地图判断

<script type="text/javascript">
$(function(){
var _nava= $('.nav .nav-wrapper a');
var _url = window.location.href;
var _host = window.location.host;
var _type = $('.news .position-search .position-search-wrapper .position a').eq(1).text();//网站地图“首页>新闻类别>新闻详情”
for(var i = 0; i<_nava.length ; i++){
var _atext = _nava.eq(i).text();
var _astr = _nava.eq(i).attr('href');
if(_url.indexOf(_astr) != -1 || _atext == _type){//地图的类别和导航的文本对比,相同在该导航添加active
_nava.eq(i).addClass('active').siblings().removeClass('active');
}else if(_url == ('http://'+_host+'/')){
_nava.eq(0).addClass('active').siblings().removeClass('active');
}
}
})
</script>

  

最新文章

  1. MobaXterm.9.4|ssh连接工具
  2. Win8.1开机黑屏一段时间才能登录
  3. tornado 路由系统----扩展(include)
  4. CSS自适应布局(左右固定 中间自适应或者右侧固定 左侧自适应)
  5. python 3.5.2 install pillow
  6. js中arguments的用法
  7. [知识整理]Java集合
  8. webbench详解
  9. POJ 1322 Chocolate(母函数)
  10. Android Dock底座应用开发
  11. 趣味Python入门(一):初识Python
  12. Apache Commons Pool2 源码分析 | Apache Commons Pool2 Source Code Analysis
  13. JavaScript学习笔记:数组reduce()和reduceRight()方法
  14. 特殊集合(stack、queue、hashtable的示例及练习)
  15. js求指定时间的周一和周日
  16. Html5 localStorage 缓存
  17. 【WebService】WebService基础知识(一)
  18. Android Touch事件派发流程源码分析
  19. Function 对象 &amp; anonymous 匿名函数
  20. 工作经验:Java 系统记录调用日志,并且记录错误堆栈

热门文章

  1. (转)AspNetPager查询分页问题(点击页码,不再是查询后的数据集)viewstate解决
  2. C++深层复制解决指针悬挂
  3. Jquery函数实现时间显示模式为更新于+被当前时间减去后剩余的时间值(例如:更新于三小时前)的处理。
  4. [Search Engine] Compression in Inverted Index
  5. shell编程-1到100的求和与冒泡排序
  6. 【面试】Spring问答Top 25
  7. -webkit-appearance: none;
  8. Lua绑定C++类
  9. mongodb 基本语法
  10. 手机QQ v4.2 有感