a.html页面向b.html页面传递参数,
a.html页面代码如下:
<a href="b.html?id=1">
b.html页面关键代码如下:
/******** 获取Url查询参数 公共方法*********************************************
*/
function getParams(name, href) {
var href = href || window.location.href,
value = '';
if (name) {
var reg = new RegExp(name + '=([^&]*)', 'g');
href.replace(reg, function($0, $1) {
value = decodeURI($1);
});
} else {
value = {};
var reg = /\b(\w+)=([^\/&]*)/g;
href.replace(reg, function($0, $1, $2) {
value[$1] = decodeURI($2);
});
}
return value;
};
/*********************************************************************/
$(function(){
获取传递的id参数
var id=getParams("id");
});