1.如何把url中的参数字符串转换为对象。
var str = b[][ct][wx][][yq]=2;
str = {
b:[{
ct:{
wx:[{
yq:2
}]
}
}]
}
1.如何把url中的参数字符串转换为对象。
var str = b[][ct][wx][][yq]=2;
str = {
b:[{
ct:{
wx:[{
yq:2
}]
}
}]
}
function getParamByNameInUrl (name){
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
const regex = new RegExp("[\\?&]" + name + "=([^&#]*)");
const results = regex.exec(location.search);
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
10 回答11.6k 阅读
2 回答3.1k 阅读✓ 已解决
3 回答2.7k 阅读✓ 已解决
4 回答2.2k 阅读✓ 已解决
3 回答1.2k 阅读✓ 已解决
3 回答1.9k 阅读✓ 已解决
3 回答806 阅读✓ 已解决
https://developer.mozilla.org/zh-CN/docs/Web/API/URL/searchParams