js获取当前页面的参数

来源:互联网 发布:找淘宝推广团队 编辑:程序博客网 时间:2024/06/05 03:21
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>js获取参数</title><Script language="javascript"> function GetRequest() { var url = location.search; //获取url中"?"符后的字串 var theRequest = new Object(); if (url.indexOf("?") != -1) { var str = url.substr(1); strs = str.split("&"); for(var i = 0; i < strs.length; i ++) { theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]); } } return theRequest; } </Script> <Script language="javascript"> var Request = new Object(); Request = GetRequest(); var name,age; name = Request['name']; age = Request['age']; alert(age);</Script> </head><body>请在浏览器输入url:http://127.0.0.1/jsgetp.php?name=123&age=999</body></html>

0 0
原创粉丝点击