美文网首页
点击li跳转页面并添加class

点击li跳转页面并添加class

作者: LuckyS007 | 来源:发表于2017-04-21 18:11 被阅读1949次
1.1跳转页面同时添加activer

js

$(document).ready(function(){
  [location.pathname]
-- 返回URL的域名后的部分。例如 http://www.dreamdu.com/xhtml/list   返回/xhtml/list
**pathname**,中文"路径名称"

    var local = window.location.pathname; //获取url
    localName = local.split("/");  //去掉'/' localName([1])表示第一个xhtml
           $e = $(".bottombox").find('.'+ localName[1]);
           $e.addClass('activer').siblings().removeClass('activer');
// 特殊情况,但第一个相同,第二个不等于conbine时,做判断
    if(localName[2] != 'combine'){
         $e.addClass('activer').siblings().removeClass('activer');
    }else{
        $(".li2").addClass('activer').siblings().removeClass('activer');
    }    

})

html

<div class="bottombox">
   <ul>
       <li class="li1 index goods activer" onclick="go('/index')">
       </li>
       <li class="li2" onclick="go('/goods/classify')" data-local="">
       </li>
       <li class="li3 like" onclick="go('/like/list')">
       </li>
       <li class="li4 user order cart address" onclick="goIfLogin('/user/detail')">
       </li>
       <li class="li5 service" onclick="go('/service/list')">
       </li>
   </ul>
</div>

css

.bottombox {
  z-index: 0;
  width: 100%;
  height: auto;
  position: fixed;
  bottom: 0;
  background-color: #F0F0F0;
  text-align: center;
  border-top: 1px solid #cacaca;
}
.bottombox li {
  float: left;
  width: 20%;
  padding: 7% 0;
  font-size: 10px;
  font-weight: bolder;
  color: #a9a9a9;
  border-right: 1px solid #cacaca;
  box-sizing: border-box;
  cursor: pointer;
  position: relative;
  background-size: 100% auto;
  
}
.bottombox li:after{
  display: block;
  content: ".";
  width: 100%;
  height: 100%;
  position: absolute;
  left: 0;
  top: 0;
}
.bottombox li:first-child:after {
  border-left: 0;
  background: url('/images/APPicon/tab/fa_icon.png') center center no-repeat;
  background-size: 100% 100%;
}
 .bottombox li.activer:first-child:after{
  border-left: 0;
  background: url('/images/APPicon/tab/fa_icon1.png') no-repeat;
  background-size: 100% 100%;
} 
Paste_Image.png
1.2跳转页面同时添加activer并传入参数
functionn go(url){
location.href = url + '?invitation=' + $("#dealerName").val();
}

<a href="javascript:void(0);" onclick="go('/ctive/aaaa')" data-url="/ctive/aaaa">aaaa</a>
<a href="javascript:void(0);" onclick="go('/ctive/bbb')" data-url="/ctive/bbbb">bbbb</a>
<a href="javascript:void(0);" onclick="go('/ctive/cccc')" data-url="/ctive/cccc">cccc</a>

$('.left_nav_act a').each(function () {
        if ($(this).attr("data-url") == String(window.location.pathname))
            $(this).addClass('activerA');
    });

相关文章

  • 点击li跳转页面并添加class

    1.1跳转页面同时添加activer js html css 1.2跳转页面同时添加activer并传入参数

  • 前台服务

    例如点击通知跳转到Three.class页面,点击返回时回退到Second.class,需要添加

  • 功能思路

    1、添加点击跳转添加页面,填完信息之后,点击添加调接口,跳到页面2、删除点击事件,调接口,确定,3、修改添加动态路...

  • 蓝桥第四课-新增商品页面开发以及接口调用

    这节课来实现新增商品,首先是点击【添加商品】按钮实现跳转页面,在定义点击方法跳转页面之前,要先新建一个页面addS...

  • Native和flutter相互交互

    场景:Native点击按钮跳转flutter页面并传参 Android页面 Dart页面 参照:https://w...

  • flutter 跳转页面传递参数 返回页面带参数

    点击跳转 页面 跳转后页面 还有另外一种跳转页面 跳转接收页面

  • app下webview问题

    情景:app-点击banner-打开A页面(点击A某个按钮跳转)-B页面(点击B某个按钮跳转)-C页面(点击C某个...

  • 页面刷新跳到当前菜单栏

    点击的时候用cookie进行记录 页面进来时候读取cookie 跳转新页面指定li也可以用此方法,需要设置cook...

  • 六、url链接

    1.页面跳转 在网站中我们经常会遇到,页面跳转的情况,比如点击登录,可以跳转到登录页面,点击注册可以跳转到注册页面...

  • 经销商报价配置表task划分

    前端 1、点击按钮跳转页面。 创建经销商报价配置表按钮创建页面,添加页签添加路由 2、在该页面中创建经销商报价配置...

网友评论

      本文标题:点击li跳转页面并添加class

      本文链接:https://www.haomeiwen.com/subject/sctjzttx.html