<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="UrlDemo._Default" %>
<!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 runat="server">
<title></title>
<script language="javascript" type="text/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;
}
function test() {
var Request = new Object();
Request = GetRequest();
var a = Request["a"];
var b = Request["b"];
alert(a);
alert(b);
}
//输入url:(http://localhost:3195/Default.aspx?a=1&b=2)
</script>
</head>
<body οnlοad="test();">
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
js 获取地址传参
最新推荐文章于 2022-08-24 08:39:22 发布