码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2018-10-24 22:17:05      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:foreach   null   split   sub   item   length   cti   substr   字符串   

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;
}

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

标签:foreach   null   split   sub   item   length   cti   substr   字符串   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!