当前位置 : 主页 > 网络编程 > JavaScript >

截取get请求的函数

来源:互联网 收集:自由互联 发布时间:2021-06-30
gistfile1.txt getParameterByName = function (a,url) { a = a.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); var c = new RegExp("[\\?]" + a + "=([^#]*)"), b = c.exec(location.search); if(url){ b = c.exec(url); } return b == null ? "" : decode
gistfile1.txt
getParameterByName =  function (a,url) {
    a = a.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    var c = new RegExp("[\\?&]" + a + "=([^&#]*)"), b = c.exec(location.search);
    if(url){
        b = c.exec(url);
    }
    return b == null ? "" : decodeURIComponent(b[1].replace(/\+/g, " "))
}
两个参数,一个是你需要截取的字段,一个是get请求网址
 
getParameterByName("fr","https://baike.baidu.com/item/jpgraph/5253147?fr=aladdin")//aladdin
网友评论