一般情況跳轉頁面我們只需要帶一些id 或者狀態值 這樣的跳轉我們就可以簡單的拼接在url 后面
location.href="/payment/success?order_no="+order_no; 在第二個頁面
var id="<?php echo intval($_GET['order_no']); ?>"; 這樣獲取
還有就是帶的數據量比較大 比如 手機號 登錄密碼 這些盡量不要拼接在url 后面 這時就用到了緩存
在跳轉的時候 我們需要設置上
sessionStorage.setItem('mobile', mobile);
sessionStorage.setItem('code', code);
location.href = '/person/modbile';
在modbile 頁面上get 方式去獲取就行了
var mobile = sessionStorage.getItem('mobile');
var code = sessionStorage.getItem('code');
原生獲取
$.getUrlParam = function(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if (r != null) return unescape(r[2]);
return null;
}
var id= $.getUrlParam('id')