demo.htm
<html lang="en">
<head>
<title>demo页面</title>
</head>
<body>
<a href="text.htm?id=321&name=zhangsan">向text页面传参数</a>
</body>
</html>
text.htm
<html lang="en">
<head>
<title>text页面</title>
<!--引入Jquery-->
<script type="text/javascript" src="jquery.1.7.2.min.js"></script>
<script type="text/javascript">
<!--
//获取URL
$(function(){
var params = $.getURLparams(location.href)
alert("ID:"+params.querys.id+" NAME:"+params.querys.name);
});
//解析URL
$.getURLparams=function(url,looseMode)
{
var o={
key:['source','protocol','authority','userInfo','user','pass','host','port','relative','path','dir','file','query','anchor'],
q:{
name:'querys',
parser:/(?:^|&)([^&=]*)=?([^&]*)/g
},
parser:{
strict:/^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
loose:/^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/\/?)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
}
},mode=(looseMode?'loose':'strict'),m=o.parser[mode].exec(url),uri={},i=14;
while(i--){
uri[o.key[i]]=m[i]||'';
}
uri[o.q.name]={};
uri[o.key[12]].replace(o.q.parser,function($0,$1,$2){
if($1) uri[o.q.name][$1]=$2;
});
return uri;
};
//-->
</script>
</head>
<body>
</body>
</html>
用fireBug可看到