js获取url参数值
效果:
代码:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <script type="text/javascript"> window.onload = function(){ document.getElementById("username").value = getUrlParam("username"); document.getElementById("nickname").value = getUrlParam("nickname"); } function getUrlParam(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); var r = decodeURI(window.location.search).substr(1).match(reg); if (r != null){ return decodeURI(unescape(r[2])); } return null; } </script> <title>点击获取url参数值</title> </head> <body> <a href="getUrlParam.html?username=hello你好&nickname=world世界" target="_blank">点击获取url参数值</a><br /> 参数username的值:<input id="username" readonly/><br /> 参数nickname的值:<input id="nickname" readonly/> </body> </html>