The content of this article is about JS parsing url parameters into objects. It has certain reference value. Now I share it with everyone. Friends in need can refer to it
Implementation ideas: Please see the log and print results
// url参数解析 function getUrlkey(url) { var params = {}; var urls = url.split("?"); console.log('1_分割url:', urls) var arr = urls[1].split("&"); console.log('2_分割urls[1]:', arr) for (var i = 0, l = arr.length; i < l; i++) { var a = arr[i].split("="); console.log('3_遍历 arr 并分割后赋值给a:', a[0], a[1]) params[a[0]] = a[1]; console.log('4_a给params对象赋值:', params) } console.log('5_结果:', params) return params; }
console.log(6,getUrlkey('http//aaa/txt.php?a =1&b=2&c=3'))
Print result:
How to get url parameters in JS
The above is the detailed content of JS parses url parameters into objects. For more information, please follow other related articles on the PHP Chinese website!