正则表达式获取URL参数


使用到的正则表达式:

[^\?&]?参数名=[^&]+

document.location.getURLPara = function (name) {
    var reg = new RegExp("[^\?&]?" + encodeURI(name) + "=[^&]+");
    var arr = this.search.match(reg);
    if (arr != null) {
        return decodeURI(arr[0].substring(arr[0].search("=") + 1));
    }
    return "";
}

使用方法:

例如地址:http://localhost/URLParas/Test.aspx?name=mo&帅不帅=太帅了

alert(document.location.getURLPara("帅不帅"));


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM