亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

JS攜帶參數(shù)實(shí)現(xiàn)頁面跳轉(zhuǎn)功能

 更新時間:2022年11月24日 10:52:08   作者:穎兒?^▽^?  
這篇文章主要介紹了js攜帶參數(shù)實(shí)現(xiàn)頁面跳轉(zhuǎn),實(shí)現(xiàn)方法也很簡單,方式一是跳轉(zhuǎn)路徑攜帶參數(shù),第二種方法是通過sessionStorage傳遞,需要的朋友可以參考下

js攜帶參數(shù)頁面跳轉(zhuǎn)

方法一:跳轉(zhuǎn)路徑攜帶參數(shù)

第一個頁面:

location.replace("user.html?username=" + username + "&userPsd=" + userPsd);

跳轉(zhuǎn)后的頁面

//獲取路徑攜帶的參數(shù)
var username = (location.search).substring(((location.search).indexOf("=") + 1), (location.search).indexOf("&"));
//傳遞一個參數(shù)時,用下面的獲取
 var password = (location.search).substring(((location.search).lastIndexOf("=") + 1), (location.search).length);

缺點(diǎn):跳轉(zhuǎn)后的路徑后面攜帶參數(shù)和值

.../html/user.html?username=aaa&userPwd=111

方法二: sessionStorage傳遞

sessionStorage屬性允許在瀏覽器中存儲 key/value 對的數(shù)據(jù),但sessionStorage 用于臨時保存同一窗口(或標(biāo)簽頁)的數(shù)據(jù),在關(guān)閉窗口或標(biāo)簽頁之后將會刪除這些數(shù)據(jù)。

頁面一:

//獲取輸入框的值
var username = document.getElementById("username").value;
var userPsd = document.getElementById("password").value;
//跳轉(zhuǎn)路徑
location.replace("user.html");
//設(shè)置sessionStorage:-----------主要代碼-------------------------------
window.sessionStorage.setItem('username', username);           window.sessionStorage.setItem('password', userPsd);

可以在瀏覽器中查看:運(yùn)行后瀏覽器右鍵-檢查

頁面二:

//在跳轉(zhuǎn)后頁面,通過getItem方法來獲取
var username = window.sessionStorage.getItem('username');
var password = window.sessionStorage.getItem('password');

具體數(shù)據(jù)可根據(jù)實(shí)際要求更改

到此這篇關(guān)于js攜帶參數(shù)實(shí)現(xiàn)頁面跳轉(zhuǎn)的文章就介紹到這了,更多相關(guān)js攜帶參數(shù)實(shí)現(xiàn)頁面跳轉(zhuǎn)內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論