- var urlOption={
- _set:function (name,val,jump=false) {
- let thisURL = String(document.location);
- if(thisURL.indexOf(name+'=') > 0){
- let v = this._get(name);
- if(v != null) {
- thisURL = thisURL.replace(name + '=' + v, name + '=' + val);
- }else{
- thisURL = thisURL.replace(name + '=', name + '=' + val);
- }
- }else{
- if(thisURL.indexOf("?") > 0){
- thisURL = thisURL + "&" + name + "=" + val;
- }else {
- thisURL = thisURL + "?" + name + "=" + val;
- }
- }
- if(jump){
- location.href = thisURL;
- }else{
- return thisURL;
- }
- },
- _get:function (name) {
- let reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
- let r = window.location.search.substr(1).match(reg);
- if(r!=null)return unescape(r[2]); return null;
- },
- _del:function (name) {
- let thisURL = String(document.location);
- if (thisURL.indexOf(name+'=') > 0){
- let arr_url = thisURL.split('?');
- let base = arr_url[0];
- let arr_param = arr_url[1].split('&');
- let index = -1;
- for (let i = 0; i < arr_param.length; i++) {
- let paired = arr_param[i].split('=');
- if (paired[0] === name) {
- index = i;
- break;
- }
- }
- if (index === -1) {
- return thisURL;
- }else{
- arr_param.splice(index, 1);
- if(arr_param.length){
- return base + "?" + arr_param.join('&');
- }else{
- return base ;
- }
- }
- }else{
- return thisURL;
- }
- }
- }
复制代码
|