url

头像
suipa
    阅读 1 分钟
    var url = "www.baidu.com";
    function getKey(key){
        
        let urls = url.split('?')[1]?url.split('?')[1]:'';
        if(!urls){
            console.log('没有参数');
            return;
        }
        let arrKeys = urls.split('&');
        var arr,name,value,flag;
        for(var i in arrKeys){
            arr = arrKeys[i].split("=");
            name = arr[0];
            value = arr[1];
            if(key == name){
                return value;
            };
            console.log(i,arrKeys.length-1)
            if(i == arrKeys.length-1){
                return "无此参数"
            }
        }
    };
    getKey('aa')

    suipa
    237 声望16 粉丝

    前端程序猿