jq点击事件跳转页面 及 页面跳转 传参 ,页面接收传参判断 tab显示选中

jq 页面点击事件跳转


 <div class="tab">
     <div class="tab-list  " path="./baojia.html">
       <p class="text">报价留言</p>
       <div class="line"></div>
     </div>
     <div class="tab-list tab-active" path="./shop.html">
       <p class="text">商品留言</p>
       <div class="line"></div>
     </div>
     <div class="tab-list " path="./xunjia.html">
       <p class="text">优惠活动询价</p>
       <div class="line"></div>
     </div>
   </div>

 // tab跳转方法
  $(".tab .tab-list").click(function () {
    location.replace($(this).attr("path"));
  });

返回上一页

 // 跳转
  $(".return").click(function (event) {
    event.stopImmediatePropagation();
    window.history.go(-1);
  });

页面跳转传参

 // list详情跳转
  $(document).on("click", ".list", function () {
    window.location.href = "./konwReaduce.html?" + "td=" + "3"; //携带参数跳转
  });

页面接收传参 判断显示tab选中

  <div class="tab">
   <div class="tab-list" path="../jiaoliu/index.html">
      <p class="text">羽绒交流</p>
      <div class="line"></div>
    </div>
    <div class="tab-list" path="./information.html">
      <p class="text">羽绒资讯</p>
      <div class="line"></div>
    </div>
    <div class="tab-list" path="./knowledge.html">
      <p class="text">羽绒知识</p>
      <div class="line"></div>
    </div>
    <div class="tab-list" path="./Dishonesty.html">
      <p class="text">失信曝光</p>
      <div class="line"></div>
    </div>
  </div>


 // 判断哪个tab 高亮
  function init() {
    let obj = this.getParams(window.location.href);
    let code = obj.td;
    $(".tab-list").each(function (idx, el) {
      console.log(idx);
      if (idx == code) {
        $(this).addClass("tab-active");
      }
    });
  }
  init();

  // 截取code字符串
  function getParams(url) {
    let obj = {};
    let index = url.indexOf("?"); // 看url有没有参数
    // console.log("index",index);
    let params = url.substr(index + 1); // 截取url参数部分 id = 1 & type = 2
    //console.log(params);
    if (index != -1) {
      // 有参数时
      let parr = params.split("&"); // 将参数分割成数组 ["id = 1 ", " type = 2"]
      for (let i of parr) {
        // 遍历数组
        let arr = i.split("="); // 1) i id = 1   arr = [id, 1]  2)i type = 2  arr = [type, 2]
        obj[arr[0]] = arr[1]; // obj[arr[0]] = id, obj.id = 1   obj[arr[0]] = type, obj.type = 2
      }
    }
    return obj;
  }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值