您好,登錄后才能下訂單哦!
本篇內容主要講解“js怎么獲取瀏覽器的參數”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“js怎么獲取瀏覽器的參數”吧!
實例如下:
function getQueStr(url, ref) //取獲參數值 { var str = url.substr(url.indexOf('?') + 1); if (str.indexOf('&') != -1) { var arr = str.split('&'); for (i in arr) { if (arr[i].split('=')[0] == ref) return arr[i].split('=')[1]; } } else { return url.substr(url.indexOf('=') + 1) } } function setQueStr(url, ref, value) //設置參數值 { var str = ""; if (url.indexOf('?') != -1) str = url.substr(url.indexOf('?') + 1); else return url + "?" + ref + "=" + value; var returnurl = ""; var setparam = ""; var arr; var modify = "0"; if (str.indexOf('&') != -1) { arr = str.split('&'); for (i in arr) { if (arr[i].split('=')[0] == ref) { setparam = value; modify = "1"; } else { setparam = arr[i].split('=')[1]; } returnurl = returnurl + arr[i].split('=')[0] + "=" + setparam + "&"; } returnurl = returnurl.substr(0, returnurl.length - 1); if (modify == "0") if (returnurl == str) returnurl = returnurl + "&" + ref + "=" + value; } else { if (str.indexOf('=') != -1) { arr = str.split('='); if (arr[0] == ref) { setparam = value; modify = "1"; } else { setparam = arr[1]; } returnurl = arr[0] + "=" + setparam; if (modify == "0") if (returnurl == str) returnurl = returnurl + "&" + ref + "=" + value; } else returnurl = ref + "=" + value; } return url.substr(0, url.indexOf('?')) + "?" + returnurl; } function delQueStr(url, ref) //刪除參數值 { var str = ""; if (url.indexOf('?') != -1) str = url.substr(url.indexOf('?') + 1); else return url; var arr = ""; var returnurl = ""; var setparam = ""; if (str.indexOf('&') != -1) { arr = str.split('&'); for (i in arr) { if (arr[i].split('=')[0] != ref) { returnurl = returnurl + arr[i].split('=')[0] + "=" + arr[i].split('=')[1] + "&"; } } return url.substr(0, url.indexOf('?')) + "?" + returnurl.substr(0, returnurl.length - 1); } else { arr = str.split('='); if (arr[0] == ref) return url.substr(0, url.indexOf('?')); else return url; } }
到此,相信大家對“js怎么獲取瀏覽器的參數”有了更深的了解,不妨來實際操作一番吧!這里是億速云網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。