本文转自:http://blog.youkuaiyun.com/salc3k/article/details/7286296
代码示例:
1.html:
<!DOCTYPE html>
<html>
<head>
<title></title>
<style type='text/css'>
</style>
</head>
<body>
</body>
<script type='text/javascript' src='http://code.jquery.com/jquery-1.8.2.js'></script>
<script type='text/javascript' src='jqueryPlugin.js'></script>
<script type='text/javascript'>
$(document).ready(function(){
// 访问该页面时,在url末尾添加?picid=8
console.log(window.location.href);
console.log($.getUrlParam('picid'));
console.log(getUrlParam('picid'));
});
function getUrlParam(name){
//构造一个含有目标参数的正则表达式对象
var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
//匹配目标参数
var r = window.location.search.substr(1).match(reg);
//返回参数值
if (r!=null) return unescape(r[2]);
return null;
}
</script>
</html>
jqueryPlugin.js:
<!DOCTYPE html>
<html>
<head>
<title></title>
<style type='text/css'>
</style>
</head>
<body>
</body>
<script type='text/javascript' src='http://code.jquery.com/jquery-1.8.2.js'></script>
<script type='text/javascript' src='jqueryPlugin.js'></script>
<script type='text/javascript'>
$(document).ready(function(){
// 访问该页面时,在url末尾添加?picid=8
console.log(window.location.href);
console.log($.getUrlParam('picid'));
console.log(getUrlParam('picid'));
});
function getUrlParam(name){
//构造一个含有目标参数的正则表达式对象
var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
//匹配目标参数
var r = window.location.search.substr(1).match(reg);
//返回参数值
if (r!=null) return unescape(r[2]);
return null;
}
</script>
</html>
8
8