点击某链接跳转到另一页面并在页面执行某链接传参的点击方法

一、解释

点击A页面跳转到B页面,在跳转时,A页面传参X到B页面,并且在B页面执行点击方法,即:$("X").click();

二、执行点击跳转

<a href="#" class="text-white text-uppercase" onclick="openReport('.a-nav')">公司简介</a>
<script>
    function openReport(a) {
      // window.open("./about_list.html?flag=true&A=" + a, 'newwindow', 'height=1100,width=1400');
      window.open("./about_list.html?flag=true&A=" + a);
    }
  </script>

三、接受传递的参数并执行点击时间

$(function () {
      var url = window.location.href; //获取当前浏览器的url  
      index = url.indexOf("flag"); //判断当前url是否有flag,如果有,说明是从A页面跳转而来的,就执行下面的程序
      if (index != -1) { //由A页面跳转而来
        var url = location.search; //获取url中"?"符后的字串
        var theRequest = new Object();
        if (url.indexOf("?") != -1) {
          var str = url.substr(1);
          strs = str.split("&");
          for (var i = 0; i < strs.length; i++) {
            theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
          }
        }
        var navbutton = theRequest.A;
        $(theRequest.A).click();
        console.log(theRequest.A);
        return theRequest;
      }
    })
theRequest得到的是参数对象

猜你喜欢

转载自www.cnblogs.com/wangyuxue/p/11993382.html