最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時(shí)間: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ù)

第一個(gè)頁面:

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

跳轉(zhuǎn)后的頁面

//獲取路徑攜帶的參數(shù)
var username = (location.search).substring(((location.search).indexOf("=") + 1), (location.search).indexOf("&"));
//傳遞一個(gè)參數(shù)時(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屬性允許在瀏覽器中存儲(chǔ) key/value 對(duì)的數(shù)據(jù),但sessionStorage 用于臨時(shí)保存同一窗口(或標(biāo)簽頁)的數(shù)據(jù),在關(guān)閉窗口或標(biāo)簽頁之后將會(huì)刪除這些數(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)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論

安西县| 临桂县| 永川市| 灵川县| 抚远县| 广南县| 康保县| 南丰县| 襄城县| 深圳市| 来凤县| 河南省| 兴国县| 寿宁县| 诏安县| 佳木斯市| 连州市| 西乡县| 思茅市| 德阳市| 合川市| 胶南市| 临邑县| 萍乡市| 黎城县| 安顺市| 古田县| 延安市| 崇义县| 吉木萨尔县| 马龙县| 永兴县| 曲周县| 成武县| 成安县| 怀化市| 藁城市| 深圳市| 漾濞| 咸丰县| 拜城县|