下面小編就為大家帶來一篇淺談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中文網其他相關文章!