window.location.href携带参数
时间: 2023-10-20 19:31:17 浏览: 105
window.location.href可以用于页面跳转并携带参数。例如,可以使用以下代码将参数传递给另一个页面:
window.location.href = "./punch/clock_frm.html?modFlag=" + modFlag + "&role=" + role;
这样就可以将modFlag和role的值作为参数传递到clock_frm.html页面中。
另外,你还可以在新页面中接收参数并将其转换为可用的json格式。可以使用以下代码来实现:
var url = location.search; //获取url中"?"符后的字串
var theRequest = new Object();
if (url.indexOf("?") != -1) {
var str = url.substr(1);
var strs = str.split("&");
for (var i = 0; i < strs.length; i++) {
theRequest[strs[i].split("=")] = decodeURIComponent(strs[i].split("="));
}
console.log(theRequest);
}
这样,theRequest对象中就包含了从参数中提取出的键值对。
总之,window.location.href可以用于页面跳转并携带参数,然后可以在目标页面中接收和处理这些参数。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [转载--window.location.href传参/传值汇总](https://blog.csdn.net/weixin_47382065/article/details/120264692)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *3* [window.location.href传递js对象参数及获取参数](https://blog.csdn.net/qq_17152035/article/details/73692750)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文