JS通过url获取参数

xiaoxiao2021-02-28  43

//获取url中的参数 function getQueryString(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); var result = window.location.search.substr(1).match(reg); if (result != null) { return decodeURIComponent(result[2]); } else { return null; } }

比如要获取

https://mp.csdn.net/?code=123

中的code

var code = getQueryString('code');
转载请注明原文地址: https://www.6miu.com/read-2622472.html

最新回复(0)