码迷,mamicode.com
首页 > Web开发 > 详细

正则表达式获取URL参数

时间:2016-05-25 15:10:55      阅读:251      评论:0      收藏:0      [点我收藏+]

标签:

使用到的正则表达式:

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

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("帅不帅"));

正则表达式获取URL参数

标签:

原文地址:http://www.cnblogs.com/ZC_Mo-Blog/p/5526776.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!