html传值 location.search取
$(function() { var url = decodeURI(location.search); if (url.indexOf("?") != -1) { var str = url.substr(1) strs = str.split("&"); var HSCode = strs[0]; var HSCode = HSCode.substr(7); alert(HSCode); var HSName = strs[1]; var CargoName = HSName.substr(7); alert(CargoName); } });
截字符串~~
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
方法二(转自边城):
function getParamsObject(url) { var params = url.replace(/^.*\?|#.*$/g, ""); var obj = {} params.split("&").forEach(function(pair) { pair = decodeURIComponent(pair); var m = pair.match(/^(.*?)(?:=(.*))?$/); var key = m[1]; var value = m[2]; if (typeof value === "undefined") { return; } if (obj.hasOwnProperty(key)) { var v = obj[key]; if (Array.isArray(v)) { v.push(value); } else { obj[key] = [v, value]; } } else { obj[key] = value; } }); return obj; }