举个例子:假如从
A页面
跳转到B页面
,并携带参数convenient
;然后在B页面
那里接收到该参数。
A页面
function transformPage() {
var convenient = $('select[name="convenient"]').val();
window.location.href = "{:url('finances/listtoexamine')}?convenient="+convenient; // 跳转页面并携带参数convenient
}
B页面
var get_url = location.search; //获取url中"?"符及其后面的字符串 ('?convenient=1')
var theRequest = new Object(); // 自定义一个空对象 {}
if ( get_url.indexOf( "?" ) != -1 ) {
// 如果get_url里面包含了"?"符
var str = get_url.substr(1); //substr()方法返回从参数值开始到结束的字符串,即去掉"?"符;
var strs = str.split("&");
for ( var i = 0; i < strs.length; i++ ) {
theRequest[strs[i].split("=")[0]] = (strs[i].split("=")[1]);
}
}
console.log( theRequest ); //此时的theRequest就是我们需要的参数的对象合集 {convenient: '1'}
if(theRequest.convenient && theRequest.convenient != '') {
$('select[name="convenient"]').val(theRequest.convenient);
}
参考博文:https://blog.csdn.net/qq_29072049/article/details/80221694