decodeURIComponent() 函数可对 encodeURIComponent() 函数编码的 URI 进行解码。
上一页传参:
back(){
window.location.href = "groupOptimizationList.html?lastappUser=" + encodeURIComponent("" + JSON.stringify(this.lastappUser))
}
在下一页面接收参数时使用:
var appUser = decodeURIComponent(escape(this.getQueryString('lastappUser')))
this.lastappUser = JSON.parse(appUser);
// 获取参数
getQueryString(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
if (r != null && r[2] != "false")
return unescape(r[2]);
return false;
},
本文介绍了在JavaScript中如何使用decodeURIComponent和encodeURIComponent函数来处理URI编码。在页面跳转时,使用encodeURIComponent对参数进行编码,然后在目标页面通过decodeURIComponent和escape结合getQueryString方法进行解码和解析,从而正确获取并使用URL参数。

2741

被折叠的 条评论
为什么被折叠?



