js截取路径后挂载的参数

function getQueryString(name) {
     var queryObj = {};
     var search = location.search.slice(1).split('&');
     console.log(search);
     
     search.forEach((value, index, array) => {
         var t = value.split('=');
         queryObj[t[0]] = t[1];
     });
     return queryObj[name];
 }
//比如你的路径是http://baidu.com/index.html?dev=1&template=1,想要获取template
console.log(getQueryString("template"))   //1

你可能感兴趣的:(前端,js,javascript,es6,前端)