URL拿值
;(function(win, undefined){ const URL_TOOL = { //获取url中的所有key,value值,返回对象 getUrlKeyVal(URL) { let _options = {}; //或者 let urlStr = URL.match((/\?([\w\W]*)/) || [, '/'])[1]; let urlStr = URL.match(/\?.*/)[0].slice(1); urlStr.split('&').forEach(function(item, i){ _options[item.split('=')[0]] = item.split('=')[1]; }); return _options; } //--------------拿url中的某一个键的值,返回字符串 getUrlVal(URL, key) { var keyReg = new RegExp(key + "=([^&]+)"); var val = (URL.match(keyReg) || [, '/'])[1]; return val; } }; window.URL_TOOL = URL_TOOL;})(window);let SearchURL = "http://www.baidu.com/?appid=wxd9j1ad5f&body=test&device_info=1000&wode=&mch_id=10000100&nonce_str=ibuaiVxkhJA";console.log(URL_TOOL.getUrlKeyVal(SearchURL));console.log(URL_TOOL.getUrlVal(SearchURL, "appid"));
// 获取url所带参数function GetRequest() { var url = location.search; //获取url中"?"符后的字串 var theRequest = new Object(); if (url.indexOf("?") != -1) { var str = url.substr(1); strs = str.split("&"); for(var i = 0; i < strs.length; i ++) { theRequest[strs[i].split("=")[0]]=(strs[i].split("=")[1]); } } return theRequest;}// 获取url特定key valfunction GetQueryString(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)","i"); var r = window.location.search.substr(1).match(reg); if (r!=null) return (r[2]); return null;}