JS攜帶參數實現頁面跳轉功能
js攜帶參數頁面跳轉
方法一:跳轉路徑攜帶參數
第一個頁面:
location.replace("user.html?username=" + username + "&userPsd=" + userPsd);跳轉后的頁面
//獲取路徑攜帶的參數
var username = (location.search).substring(((location.search).indexOf("=") + 1), (location.search).indexOf("&"));
//傳遞一個參數時,用下面的獲取
var password = (location.search).substring(((location.search).lastIndexOf("=") + 1), (location.search).length);缺點:跳轉后的路徑后面攜帶參數和值
.../html/user.html?username=aaa&userPwd=111
方法二: sessionStorage傳遞
sessionStorage屬性允許在瀏覽器中存儲 key/value 對的數據,但sessionStorage 用于臨時保存同一窗口(或標簽頁)的數據,在關閉窗口或標簽頁之后將會刪除這些數據。
頁面一:
//獲取輸入框的值
var username = document.getElementById("username").value;
var userPsd = document.getElementById("password").value;
//跳轉路徑
location.replace("user.html");
//設置sessionStorage:-----------主要代碼-------------------------------
window.sessionStorage.setItem('username', username); window.sessionStorage.setItem('password', userPsd);可以在瀏覽器中查看:運行后瀏覽器右鍵-檢查

頁面二:
//在跳轉后頁面,通過getItem方法來獲取
var username = window.sessionStorage.getItem('username');
var password = window.sessionStorage.getItem('password');具體數據可根據實際要求更改
到此這篇關于js攜帶參數實現頁面跳轉的文章就介紹到這了,更多相關js攜帶參數實現頁面跳轉內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
js字符串截取函數substr substring slice使用對比
字符串截取函數有substr、substring以及slice等等,下面將為大家介紹下各自的使用,感興趣的朋友可以了解下2013-11-11
JavaScript基本語法_動力節(jié)點Java學院整理
這篇文章主要介紹了JavaScript基本語法,適合剛入門的同學,有興趣的可以了解下。2017-06-06
extjs中form與grid交互數據(record)的方法
這篇文章介紹了extjs中form與grid交互數據(record)的方法,有需要的朋友可以參考一下2013-08-08

