当前位置:网站首页>Get the query parameter in the address URL specify the parameter method
Get the query parameter in the address URL specify the parameter method
2022-06-27 06:48:00 【Front end of brick moving】
Get address url Medium query Parameterspecify the parameter method
Scheme 1 :( Best compatibility , But it's a little long )
function getParam(name) {
// First get # Later parameters
var getValue = function(name, str) {
// To obtain parameters name Value
var reg = new RegExp("(^|!|&|\\?)" + name + "=([^&]*)(&|$)");
// Get more ? Later parameters
var r = str.match(reg);
if (r != null) {
try {
return decodeURIComponent(r[2]);
} catch (e) {
console.log(e + "r[2]:" + r[2]);
return null;
}
}
return null;
};
var str = document.location.hash.substr(2);
var value = getValue(name, str);
if (value == null) {
str = document.location.search.substr(1);
value = getValue(name, str);
}
return value;
}
Option two : Compatibility ( Support es6 Of map Can )
function getParams(key){
var ops = {
};
window.location.href.split('?')[1].split('&').map(i => ops[(i.split('=')[0])] = i.split('=')[1]);
return ops[key]
}
Option three : Compatibility ( Support es6 Can )
- ts Unavailable , Need to change return That line
- ?. Expressed as true Just continue to follow the chain
function getParams(key){
var str = window.location.href.split('?')[1].split('&').filter(i => i.startsWith(key+'='));
return str?.[0]?.split('=')[1]
}
Basically, mainstream browsers have no problem , Generally, I use the first kind of omnipotent , But it's a little long
边栏推荐
- 面试官:用分库分表如何做到永不迁移数据和避免热点问题?
- 面试官:大量请求 Redis 不存在的数据,从而打倒数据库,你有什么方案?
- 2022 CISP-PTE(一)文件包含
- 2018年数学建模竞赛-高温作业专用服装设计
- Gaussian distribution, linear regression, logistic regression
- el-select多个时,el-select筛选选中过的值,第二个el-select中过滤上一个选中的值
- Meaning of 0.0.0.0:x
- Centos7.9 install MySQL 5.7 and set startup
- 2022 CISP-PTE(一)文件包含
- 426 binary tree (513. find the value in the lower left corner of the tree, 112. sum of paths, 106. construct a binary tree from the middle order and post order traversal sequence, 654. maximum binary
猜你喜欢

Cloud-Native Database Systems at Alibaba: Opportunities and Challenges

JVM garbage collection mechanism

SQL injection bypass (I)

AHB2APB桥接器设计(2)——同步桥设计的介绍

Altium designer 19 device silk screen label position shall be placed uniformly in batches

解决 Win10 Wsl2 IP 变化问题

小米面试官:听你说精通注册中心,我们来聊 3 天 3 夜

OPPO面试整理,真正的八股文,狂虐面试官

Block level elements & inline elements

面试官:你天天用 Lombok,说说它什么原理?我竟然答不上来…
随机推荐
The fourth question of the 299th weekly match 6103 Minimum fraction of edges removed from the tree
观测电机转速转矩
写一个 goroutine 实例, 同时练习一下 chan
[cultivation system] common regular expressions
主动学习(active learning)
C Primer Plus Chapter 11_ Strings and string functions_ Codes and exercises
Gaussian distribution, linear regression, logistic regression
[QT dot] QT download link
2022 le fichier CISP - Pte (i) contient:
日期 数据库日期 字符串 之间互相转换
SQL injection bypass (I)
TiDB 中的数据库模式概述
面试官:用分库分表如何做到永不迁移数据和避免热点问题?
聊聊领域驱动设计
multiprocessing. Detailed explanation of pool
Unrecognized VM option ‘‘
获取地址url中的query参数指定参数方法
multiprocessing.pool详解
Scala advanced_ Member access modifier
AHB2APB桥接器设计(2)——同步桥设计的介绍