js 获取url地址的参数

来源:互联网 发布:知天下资源吧手机版 编辑:程序博客网 时间:2024/05/16 08:02
var str='http://image.baidu.com/search/detail?ct=503316480&z=0&ipn=d';String.prototype.myQueryUrlPar=function(){    //this-实例str    var obj={};    var reg=/([^?=&]+)=([^?=&]+)/g;    this.replace(reg,function($0,$1,$2){        obj[$1]=$2;    })    return obj;};console.log(str.myQueryUrlPar());console.log(str.myQueryUrlPar()['z']);console.log(str.myQueryUrlPar()['ct']);console.log(str.myQueryUrlPar()['ipn']);
0 0