url

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')
相關文章
相關標籤/搜索