下面小编就为大家带来一篇浅谈javascript的url参数parse和build函数。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
Parse:
function getParam() { var param = new Object() var item = new Array(); if (location.search == "") { return param; }; var query = location.search.substring(1); var list = query.split('&'); for(var i = 0; i < list.length; i++) { item = list[i].split('='); if (typeof param[item[0]] == "undefined") { param[item[0]] = new Array(); } param[item[0]].push(item[1]); }; return param; };
Build:
function getUrlByParam(param) { var url = ""; for (field in param) { for (index in param[field]) { url += "&" + field + "=" + param[field][index]; }; }; return url == "" ? url : url.substring(1); };
以上是简单介绍javascript的url参数parse和build函数的详细内容。更多信息请关注PHP中文网其他相关文章!