str = 'http://1dwen.cn/index.php/bra...';
How to get 2 of this string;
迷茫2017-07-05 10:58:03
function GetQueryString(str, name)
{
var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
var r = str.match(reg);
if(r!=null)return unescape(r[2]); return null;
}
扔个三星炸死你2017-07-05 10:58:03
http://1dwen.cn/index.php/bra...
Do I have to use regular expressions? This can also be done using url and querystring.
var url = require('url');
var qs = require('querystring');
function getQuery(_url_){
return qs.parse(url.parse(_url_).query);
}
var q = getQuery('http://1dwen.cn/index.php/brand/hot_product?id=2');
console.log(q.id);
代言2017-07-05 10:58:03
var str = 'http://1dwen.cn/index.php/brand/hot_product?id=2';
str.match(/^(.*)\?id=(\d+)$/)[2]
我想大声告诉你2017-07-05 10:58:03
Let me write a function that takes parameter values
var str='http://1dwen.cn/index.php/brand/hot_product?id=2'
function getParmValue(str){
if(str.indexOf('?')==-1){
return false;
}else{
var s=str.slice(str.indexOf('?')+1);
var arr=s.split('=');
return arr[1];
}
}
getParmValue(str);