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

JS获取url参数

时间:2019-07-18 16:32:48      阅读:110      评论:0      收藏:0      [点我收藏+]

标签:win   获取   location   null   ret   class   xxxx   fun   turn   

/**
 * 截取?后面的参数
 *
 * @param name
 * @returns {*}
 */
function mygetURLQuery(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var hash = window.location.href.split("?")[1];
    var r = hash.match(reg);
    if (r != null) {
        return decodeURI(r[2]);
    }
    return null;
}
调用 mygetURLQuery("id") 返回 XXXX。

调用 mygetURLQuery("image") 返回 "XXXX"。

JS获取url参数

标签:win   获取   location   null   ret   class   xxxx   fun   turn   

原文地址:https://www.cnblogs.com/diandianquanquan/p/11208033.html

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