匹配?后面的值?

阅读 2.8k
4 个回答
decodeURIComponent(location.search.replace(/^\?/, '').split('=')[1])
decodeURIComponent(/orgname=([^=]+)/.exec(location.search)[1])
function getQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if(r != null){
        return decodeURI(r[2]);
    } 
    return null;
}
var url = 'http://orgname=123';
var result = new RegExp(/=.*/).exec(url)[0].substr(1);
console.log(result);

这个不用正则也可以啊,字符串分割

推荐问题