一、解釋
點擊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>
在新窗口中打開鏈接:
window.open("./about_list.html?flag=true&A=" + a, "_blank");
在原來窗口打開鏈接:
window.open("./about_list.html?flag=true&A=" + a, "_parent");
三、接受傳遞的參數並執行點擊事件
$(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得到的是參數對象