首页 > 其他 > 详细

解析浏览器地址栏查询字符串参数

时间:2018-10-24 21:34:46      阅读:256      评论:0      收藏:0      [点我收藏+]
function getQuery() {
  let search = location.search.length > 0 ? location.search.substr(1) : ‘‘;
  if (!search) return null;
  let Query = {};
  if (search.includes(‘&‘)) {
    let strArray = search.split(‘&‘);
    strArray.forEach(item => {
      if (item.includes(‘=‘)) {
        let arr = item.split(‘=‘);
        Query[decodeURIComponent(arr[0])] = decodeURIComponent(arr[1])
      }
    })
  } else {
    let arr = item.split(‘=‘);
    Query[decodeURIComponent(arr[0])] = decodeURIComponent(arr[1])
  }
  return Query;
}

解析浏览器地址栏查询字符串参数

原文:https://www.cnblogs.com/aleng-liu/p/9846032.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!