getQueryStringArgs()
来源:互联网 发布:snapseed是什么软件 编辑:程序博客网 时间:2024/06/14 20:09
function getQueryStringArgs() { // 取得要查询的字符串并去掉开头的问号 var qs = (location.search.length > 0 ? location.search.substring(1) : ""), args = {}, items = qs.length ? qs.split("&"): [], item = null, name = null, value = null, // 在for 循环中使用 i = 0, len = items.length; // 逐个将每一项目添加到args对象中 for (i; i < len; i++) { item = items[i].split("="); name = decodeURIComponent(item[0]); value = decodeURIComponent(items[1]); if (name.length) { args[name] = value } } console.log(args); return args; }