常用JS代码整理

调用此方法,可以解析携带的?之后的参数,主要用于前端页面间传参,同样适用于HTML?xxx=xxx

//
根据传递过来的参数name获取对应的值 function getParameter(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)","i"); var r = location.search.substr(1).match(reg); if (r!=null) return (r[2]); return null; }

 

截取主URL之后的部分

例如 http://localhost/gotoPage.php?param=value   可以截取获得    gotoPage.php?param=value

            getCaption(url,parameter) {
                var index = url.lastIndexOf(parameter);
                url = url.substring(index + 1, url.length);
                return url;
            }

//调用代码
this.soureUrl = this.getCaption(location.href,'/')
 

 

posted @ 2021-02-14 16:59  lutoux  阅读(57)  评论(0)    收藏  举报