第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定

獲取和修改URL的不完善版小插件

標(biāo)簽:
JavaScript
可以获取和修改url里的任意内容,并在控制台打印出来。
        尚不完善,持续修改中

html文件

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <script type="text/javascript" class="lazyload" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC" data-original="urlRequest.js"></script>
        <script>
            var urlRequestValue=new urlRequest();
            console.log(document.location);

//          urlRequestValue.setProtocol("http协议");
//          console.log(urlRequestValue.getProtocol());
//          urlRequestValue.setProtocol();
//          console.log(urlRequestValue.getProtocol());

//          urlRequestValue.setHost("主机地址");
//          console.log(urlRequestValue.getHost());
//          urlRequestValue.setHost();
//          console.log(urlRequestValue.getHost());

//          urlRequestValue.setPage("文件路径");
//          console.log(urlRequestValue.getPage());
//          urlRequestValue.setPage();
//          console.log(urlRequestValue.getPage());

            urlRequestValue.setFile("文件名");
//          console.log(urlRequestValue.getFile());
//          urlRequestValue.setFile();
//          console.log(urlRequestValue.getFile());

//          urlRequestValue.setSearchString("?后的参数字符串");
//          console.log(urlRequestValue.getSearchString());
//          urlRequestValue.setSearchString();
//          console.log(urlRequestValue.getSearchString());

//          urlRequestValue.setData("?后的参数对象");
//          console.log(urlRequestValue.getData());
//          urlRequestValue.setData();
//          console.log(urlRequestValue.getData().a);

            console.log(urlRequestValue.getNewUrl());

        </script>
    </head>
    <body>
    </body>
</html>

js文件

//获取url中的参数对象
function urlRequest(_url) {
    var content=this;
    var url = _url?String(_url):String(document.location);
    var theProtocol,thePtlVal = null;//协议
    var theHost,theHostVal = null; //服务器
    var thePage,thePageVal = null; //文件本地地址
    var theFile,theFileVal = null; //文件名
    var theSearchString,theSSVal = null; //?后的数据    
    var theRequest = {};//?后的数据对象
    //获取协议
    this.setProtocol=function(_value){
        thePtlVal =_value;      
        theProtocol=null;
        if(!_value && window.location.protocol){
//          if (url.indexOf("http://") != -1){
//              theProtocol = url.substr(0,url.indexOf("/"));
//          }
            theProtocol = window.location.protocol
        }else{
            theProtocol=_value;
        }   
    };
    this.getProtocol=function(_value){
        return theProtocol;
    };

    //获取host
    this.setHost=function(_value){
        theHostVal =_value;
        theHost=null;
        if(!_value && window.location.host){
            theHost = window.location.host;
//          if (url.indexOf("http://") != -1){
//              var str= url.substr(url.indexOf("http://")+2);
//              if(str.substr(0,str.indexOf("/")).indexOf(".") != -1){
//                  theHost = str.substr(0,str.indexOf("/"));
//              }else{
//                  theHost=null;
//              }
//          }
        }else{
            theHost=_value;
        }
    };
    this.getHost=function(_value){
        return theHost;
    };

    //获取page
    this.setPage=function(_value){
        thePageVal =_value;
        thePage=null;
        if(!_value && window.location.pathname){
            thePage=window.location.pathname;           
        }else{
            thePage=_value;
        }
    };
    this.getPage=function(_value){
        return thePage;
    };

    //获取file
    this.setFile=function(_value){
        theFileVal =_value;
        theFile=null;
        if(!_value && window.location.pathname){
            if (window.location.pathname.lastIndexOf(".") != -1){
                var str= window.location.pathname.lastIndexOf("/")+1;
                theFile=window.location.pathname.substr(str);
            }
        }else{
            theFile=_value;
        }
    };
    this.getFile=function(_value){
        return theFile;
    };

    //获取url中"?"后的字串
    this.setSearchString=function(_value){
        theSSVal =_value;
        theSearchString=null;
        if(!_value && window.location.search){
            if (window.location.search.indexOf("?") != -1) {
                var str= window.location.search.lastIndexOf("?")+1;
                theSearchString=window.location.search.substr(str);
            }
        }else{
            theSearchString=_value;
        }
    };
    this.getSearchString=function(_value){
        return theSearchString;
    };

    //获取url中"?"符后的字串对象
    this.setData=function(_value){
        theRequest = {};
        if(!_value){
            if (url.indexOf("?") != -1) {//判断后面有没有参数
                var str = url.substr(url.indexOf("?")+1);
                if(str.indexOf("#")!= -1){str=str.substr(0,str.indexOf("#"));}
                strs = str.split("&");
                for(var i = 0; i < strs.length; i ++) {
                    var indexOfadd=strs[i].indexOf("=");
                    var key=strs[i].substr(0,indexOfadd);
                    if (indexOfadd>0 && key){
                        var value=strs[i].substr(indexOfadd+1);
                        if(key in theRequest){
                            if(theRequest[key] instanceof Array){
                                theRequest[key].push(value);
                            }else{
                                theRequest[key]=[theRequest[key]];
                                theRequest[key].push(value);
                            }
                        }else{
                            theRequest[key]=value;
                        }
                    }
                }
            }
        }else{
            theRequest=_value;
        }
    };
    this.getData=function(){
        return theRequest;
    };
    this.getNewUrl=function(_url){
        content.setData();
        content.setProtocol(thePtlVal);
        content.setHost(theHostVal);
        content.setPage(thePageVal);
        content.setFile(theFileVal);
        content.setSearchString(theSSVal);
        var theNewUrl=theProtocol+"http://"+theHost+thePage+"?"+theSearchString;
        return theNewUrl;
    };
}
點(diǎn)擊查看更多內(nèi)容
1人點(diǎn)贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優(yōu)質(zhì)文章

正在加載中
感謝您的支持,我會繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊有機(jī)會得

100積分直接送

付費(fèi)專欄免費(fèi)學(xué)

大額優(yōu)惠券免費(fèi)領(lǐng)

立即參與 放棄機(jī)會
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號

舉報

0/150
提交
取消