JavaScript

超轻量级php框架startmvc

浅谈javascript的url参数parse和build函数

更新时间:2020-04-27 04:45:01 作者:startmvc
Parse:functiongetParam(){varparam=newObject()varitem=newArray();if(location.search==""){returnparam;};varquery=locatio

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函数就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。

javascript parse url