首页 > Web开发 > 详细

js 接收浏览器的参数值

时间:2014-08-19 12:42:34      阅读:324      评论:0      收藏:0      [点我收藏+]

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>修改页面</title>
<script type="text/javascript">
function GetQueryString(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
if (r != null) return unescape(r[2]); return null;
}
function GetRequest() {
var url = location.search; //获取url中"?"符后的字串
var theRequest = new Object();
if (url.indexOf("?") != -1) {
var str = url.substr(1);//去掉字符串里的 ?
strs = str.split("&"); //将字符串str 根据 & 分割成多个字符串,并存入数组strs
/*
strs[0]="i=1";
strs[1]="name=james";
*/
for (var i = 0; i < strs.length; i++) {
theRequest[strs[i].split("=")[0]] = strs[i].split("=")[1];
//theRequest.i=1
//theRequest.name="james";
}
}
return theRequest;
}
//注意:此时是在修改页面里
window.onload = function () {
var paras = GetRequest(); //获得url中的参数对象(url中的每个参数都以 该返回值 属性的方式存在)
//alert(paras.name);
document.getElementById("txtId").value = paras.i;
document.getElementById("txtName").value = paras.name;
//alert(window.location.search);//代表 url 参数字符串
}
</script>
</head>
<body>
要修改的班级信息:<br />
<input type="text" id="txtId" /><br />
<input type="text" id="txtName" />
</body>
</html>

js 接收浏览器的参数值,布布扣,bubuko.com

js 接收浏览器的参数值

原文:http://www.cnblogs.com/cdaq/p/3921588.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!