js 获取url地址的参数

xiaoxiao2021-02-28  151

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']);
转载请注明原文地址: https://www.6miu.com/read-30133.html

最新回复(0)