function getParameterByName(name, str) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(str);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
我正在使用此算法从字符串中获取值,并在互联网上找到了它
我的绳子是
mihpayid=403993715510554486&mode=CC&status=success&unmappedstatus=captured&key=JBZaLc&txnid=t39SfgBZFEFLwhxEC&amount=1000.0&addedon=2014-12-06+17%3A34%3A26&productinfo=Devthon&firstname=sasi.kanth80%40gmail.c&lastname=&address1=&address2=&city=&state=&country=&zipcode=&email=sasi.kanth80%40gmail.com
我能够获得所有的参数,例如 status
key
但是我无法获得mihpayid
作为第一个参数的值
我怎么能得到任何建议?
getParameterByName("success", data);
您可以利用此函数将形成一个展平的数组,如下所示
[key,value, anotherkey,anothervalue,...]
因此我们可以通过在键的索引中添加一个值来找到该值。
function getParameterByName(name, str) {
var arr = str.split('&').map(function(s){
return s.split('=')
}).join().split(","); // flatten the array
return decodeURIComponent(arr[arr.indexOf(name) + 1]);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句