Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
211 views
in Technique[技术] by (71.8m points)

javascript - Better way of getting queryString params of a URL on FreeMarker


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Iterate over all your params and retrieve the key and value:

function testParams() {
  // Demo hardcoded string, you use window.location.search
  const params = new URLSearchParams("testp1=123&testp2=2541"); 
  [...params].forEach(([key, val]) => document.getElementById(key).value = val);
}
window.addEventListener("load", testParams);
<input type="text" name="testp1" id="testp1" />
<input type="text" name="testp2" id="testp2" />

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...