HTML页面获取URL中的参数赋值给input输入框

时间:2024-03-22 19:52:32

如url:

http://localhost:10001/bindlist.html?eui=3.0.1.2.0.0.0.1&clientEUI=6.0.1.1.0.0.0.5

需求:

获取eui和clientEUI的值

方法:

var url = location.search; //获取url中"?“符后的字串
if (url.indexOf(”?") != -1) {
var str = url.substr(1);
strs = str.split("&");
clientEUI = decodeURIComponent(strs[1].split("=")[1].replace(“clientEUI=”,""));
eui = decodeURIComponent(strs[0].split("=")[1].replace(“eui=”,""));
$("#clientEUI").attr(“value”,clientEUI);
$("#eui").attr(“value”,eui);

}

效果如图:
HTML页面获取URL中的参数赋值给input输入框