📜  获取参数 js - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:16.186000             🧑  作者: Mango

代码示例2
let params = {};
window.location.search.slice(1).split('&').forEach(elm => {
  if (elm === '') return;
  let spl = elm.split('=');
  const d = decodeURIComponent;
  params[d(spl[0])] = (spl.length >= 2 ? d(spl[1]) : true);
});

// https://example.com/?foo=bar&best%20food=D%C3%B6ner
params['foo'] // bar
params['best food'] // Döner