在静态页面html中跳转传值
2013-11-05 11:56
337 查看
在html中通过"?"传值--------<a href="index2.html?name=caoy">静态传值</a>
在跳转到的页面index2.html中接收----var name=UrlParm.parm("name");
代码如下:
index.html:
<script type="text/javascript" src="js/getUrlParam.js"></script>
<a href="index2.html?name=caoy">静态传值</a>
index2.html:
<script type="text/javascript">
var name=UrlParm.parm("name");
alert(name);
</script>
getUrlParam.js:
UrlParm = function() { // url参数
var data, index;
(function init() {
data = [];
index = {};
var u = window.location.search.substr(1);
if (u != '') {
var parms = decodeURIComponent(u).split('&');
for (var i = 0, len = parms.length; i < len; i++) {
if (parms[i] != '') {
var p = parms[i].split("=");
if (p.length == 1 || (p.length == 2 && p[1] == '')) {// p | p=
data.push(['']);
index[p[0]] = data.length - 1;
} else if (typeof(p[0]) == 'undefined' || p[0] == '') { // =c | =
data[0] = [p[1]];
} else if (typeof(index[p[0]]) == 'undefined') { // c=aaa
data.push([p[1]]);
index[p[0]] = data.length - 1;
} else {// c=aaa
data[index[p[0]]].push(p[1]);
}
}
}
}
})();
return {
// 获得参数,类似request.getParameter()
parm : function(o) { // o: 参数名或者参数次序
try {
return (typeof(o) == 'number' ? data[o][0] : data[index[o]][0]);
} catch (e) {
}
},
//获得参数组, 类似request.getParameterValues()
parmValues : function(o) { // o: 参数名或者参数次序
try {
return (typeof(o) == 'number' ? data[o] : data[index[o]]);
} catch (e) {}
},
//是否含有parmName参数
hasParm : function(parmName) {
return typeof(parmName) == 'string' ? typeof(index[parmName]) != 'undefined' : false;
},
// 获得参数Map ,类似request.getParameterMap()
parmMap : function() {
var map = {};
try {
for (var p in index) { map[p] = data[index[p]]; }
} catch (e) {}
return map;
}
}
}();
这样就能通过html跳转传值了
在跳转到的页面index2.html中接收----var name=UrlParm.parm("name");
代码如下:
index.html:
<script type="text/javascript" src="js/getUrlParam.js"></script>
<a href="index2.html?name=caoy">静态传值</a>
index2.html:
<script type="text/javascript">
var name=UrlParm.parm("name");
alert(name);
</script>
getUrlParam.js:
UrlParm = function() { // url参数
var data, index;
(function init() {
data = [];
index = {};
var u = window.location.search.substr(1);
if (u != '') {
var parms = decodeURIComponent(u).split('&');
for (var i = 0, len = parms.length; i < len; i++) {
if (parms[i] != '') {
var p = parms[i].split("=");
if (p.length == 1 || (p.length == 2 && p[1] == '')) {// p | p=
data.push(['']);
index[p[0]] = data.length - 1;
} else if (typeof(p[0]) == 'undefined' || p[0] == '') { // =c | =
data[0] = [p[1]];
} else if (typeof(index[p[0]]) == 'undefined') { // c=aaa
data.push([p[1]]);
index[p[0]] = data.length - 1;
} else {// c=aaa
data[index[p[0]]].push(p[1]);
}
}
}
}
})();
return {
// 获得参数,类似request.getParameter()
parm : function(o) { // o: 参数名或者参数次序
try {
return (typeof(o) == 'number' ? data[o][0] : data[index[o]][0]);
} catch (e) {
}
},
//获得参数组, 类似request.getParameterValues()
parmValues : function(o) { // o: 参数名或者参数次序
try {
return (typeof(o) == 'number' ? data[o] : data[index[o]]);
} catch (e) {}
},
//是否含有parmName参数
hasParm : function(parmName) {
return typeof(parmName) == 'string' ? typeof(index[parmName]) != 'undefined' : false;
},
// 获得参数Map ,类似request.getParameterMap()
parmMap : function() {
var map = {};
try {
for (var p in index) { map[p] = data[index[p]]; }
} catch (e) {}
return map;
}
}
}();
这样就能通过html跳转传值了
相关文章推荐
- 在静态页面html中跳转传值
- 在静态页面html中跳转传值
- 在静态页面html中跳转传值
- 在静态页面html中跳转传值
- HTML页面之间跳转与传值(JS代码)
- html静态页面跳转
- 静态页面html中跳转传值的JS处理技巧
- HTML页面之间跳转与传值(JS代码)
- html间页面静态传值(根据url地址拆分字符串获取参数)
- [HTML]js实现页面跳转,页面A跳到另一个页面B.以及页面传值(中文)
- 静态html页面传值
- 静态页面html中跳转传值的JS处理技巧
- HTML页面之间跳转与传值(JS代码)
- HTML页面之间跳转传值
- html静态页面作跳转
- 静态页面跳转传值小插件
- html&nbsp;页面之间跳转和传值
- html 页面之间跳转和传值
- 静态页面html中跳转传值的JS处理技巧
- html 页面之间跳转和传值