<!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=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
//sArgName表示要获取哪个参数的值
function GetArgsFromHref(sArgName)
{
var sHref = "Untitled-2.html?id=2"//测试数据,实际情况是用window.location.href得到URL
alert(sHref);
var args = sHref.split("?");
var retval = "";
if(args[0] == sHref) /*参数为空*/
{
return retval; /*无需做任何处理*/
}
var str = args[1];
args = str.split("&");
for(var i = 0; i < args.length; i++ )
{
str = args[i];
var arg = str.split("=");
if(arg.length <= 1) continue;
if(arg[0] == sArgName) retval = arg[1];
}
//return retval;
alert(retval);
}
</script>
</head>
<input type="button" value="参数" onclick="GetArgsFromHref('id');" />
<body>
</body>
</html>