search

Home  >  Q&A  >  body text

javascript - How to intercept the parameters behind the url

I want to intercept the three groups of numbers after the id and then splice them into a string

http://localhost/360buji/Toni...

曾经蜡笔没有小新曾经蜡笔没有小新2748 days ago480

reply all(5)I'll reply

  • 怪我咯

    怪我咯2017-05-19 10:11:16

    var href = window.location.href,
        str = href.substring(href.indexOf("#")+1),
        reg = /([^&#?=]+)=(\w*)/g,
        result = [];
        
    str.replace(reg,function(str,key,val){
        result = val.split("&");
        return str;
    });
        

    This should be fine

    reply
    0
  • 阿神

    阿神2017-05-19 10:11:16

    var list = location.href.split('id=')[1].split('&')

    reply
    0
  • PHP中文网

    PHP中文网2017-05-19 10:11:16

    var str = location.href.split("=")[1].split("&");
    console.log(str[0]+str[1]+str[2]);

    reply
    0
  • 仅有的幸福

    仅有的幸福2017-05-19 10:11:16

    linkPar:function(key,v){//url value: key name, string

    v = v?v:location.href;
    return (v.match(new RegExp("(?:\?|&)"+key+"=(.*?)(?=&|$)"))||['',null])[1];  

    }

    reply
    0
  • 淡淡烟草味

    淡淡烟草味2017-05-19 10:11:16

    //Get url parameters
    function getUrlParam(name) {

     var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
     var r = window.location.search.substr(1).match(reg);
     if(r!=null)return  unescape(r[2]); return null;    

    }

    var personName = decodeURI(decodeURI(getUrlParam('personName')));//中文url参数
    var userNo = getUrlParam('userNo');//普通url参数

    reply
    0
  • Cancelreply