兩個靜態html頁面之間傳值方法

2021-10-09 15:52:21 字數 1396 閱讀 6503

a頁面 傳值給b頁面 (個人推薦使用前兩種來實現)

a頁面

window.open(`b.html?id=$`);
b頁面

let locstring = string(window.document.location.href);

function getquerystr(str)

// parameter cannot be found

return "";

} let id = getquerystr("id");

console.log(id);

b頁面

geturlparam.js

urlparam = function () ;   //鍵:索引,如

var u = window.location.search.substr(1);

if (u != '') else if (typeof (p[0]) == 'undefined' || p[0] == '') else if (typeof (index[p[0]]) == 'undefined') else }}

}})();

return catch (e)

},//獲得引數組, 類似request.getparametervalues()

paramvalues: function (o) catch (e)

},//是否含有paramname引數

hasparam: function (paramname) ,

// 獲得引數map ,類似request.getparametermap()

parammap: function () ;

try

} catch (e)

return map;

}}}();

缺點: cookie儲存是需要伺服器支援的,本地直接執行靜態檔案是實現不了的

b頁面

此處使用了jquery.cookie.js,具體用法可參照此篇文章:

優點:本地靜態檔案可支援

a頁面

b頁面

兩個靜態頁面中存值,傳值

使用了h5的localstorage.setitem 需要注意的是首先要把物件用json.stringify 轉一下,下面是 localstorage.setitem userinfo json.stringify data 下面是接收 var res null res json.parse loc...

兩個WebUserControl之間傳值

兩個webusercontrol之間傳值,網上的 有,直接從usercontrol1中定位到usercontrol2的寫法,偶合性很強,感覺不太好,於是提供另外的寫法。用乙個容器container.aspx來放兩個webusercontrol,分別是uc1和uc2。現在假設要從uc1的乙個事件觸發,...

實現兩個html頁面之間通過get方式傳值

1.第乙個html頁面 type button id btn value 點我進入第二個頁面 b1 b b2 b src js jquery.min.js script funcation else 在頁面中顯示變數 b1 html b1 b2 html b2 按鈕的單擊函式 btn click f...