JS 给url添加参数
/** * 给url添加参数 * @param key {string} 参数名称 * @param val {string} 参数值 * @return {string} */ function addOrgToUrl(key, val) { var url = window.location.href if (url.indexOf(key) > -1) { var re = eval('/(' + key + '=)([^&]*)/gi'); url = url.replace(re, key + '=' + val); } else { var paraStr = key + '=' + val; var idx = url.indexOf('?'); if (idx < 0){ url += '?'; }else if (idx >= 0 && idx != url.length - 1){ url += '&'; } url = url + paraStr; } return url; }