/** * @author Web wins * @param {object} obj need to stitch Parameter object * @return {String} **/functionObj2qs (obj) {if(!obj &&!)Object.keys (obj). length) { return""; } Else { vararr = []; for(varKeyinchobj) {Arr.push (Key+ "=" +Obj[key]); } returnArr.join ("&"); }}/** * @author Web Victory * @param {String} URL URL Address bar * @return {Object}*/functionqs2obj (URL) {varQS = Url.split ("?") [1]; vararr = []; varres = {}; if(!Qs) { //return res;}Else{arr= Qs.split ("&"); for(vari = 0, len = arr.length; i < Len; i++) { varKey = Arr[i].split ("=") [0]; varval = arr[i].split ("=") [1]; Res[key]=decodeURIComponent (Val); } } returnRes;}
Obj2qs is a parameter that converts parameters (object type parameters) to the Address bar, which can be used on Ajax and jump pages.
Qs2obj is the address bar parameter, you can call this function when you need to use the address bar parameter. The return value is an object.
/** * @author Web wins * @param {object} obj needs to stitch the parameter object * @return {String} * */function Obj2qs (obj) {if (!obj &&! Object.keys (obj). length) {return "";} else {var arr = [];for (var key in obj) {Arr.push (key + "=" + Obj[key]);} Return Arr.join ("&");}}
/** * @author Web Victory * @param {String} URL URL Address bar * @return {Object} */function qs2obj (URL) {var qs = url.split ("?") [1];var arr = [];var res = {};if (!QS) {//return res;} else {arr = Qs.split ("&"); for (var i = 0, len = arr.length; I &l T Len i++) {var key = Arr[i].split ("=") [0];var val = arr[i].split ("=") [1];res[key] = decodeURIComponent (val);}} return res;}
URL Address bar Parameters <==> objects (converting objects to address bar parameters and converting address bar parameters to objects) use functions