js获取地址栏参数

最近在工作中要用到js获取地址栏参数 ,在网上找了下。发现一个函数挺好的。但有点小错,现已经修正 。发出来跟大家分享一下。

 
//得到地址栏传递参数的函数
function get_parameter(qs)
{
        var s = window.location;
        s = s.replace("?","?&").split("&"); 
        var re = "";
        for(i=1;i<s.length;i++) {
            if(s[i].indexOf(qs+"=")==0) {
                    re = s[i].replace(qs+"=","");
            }
        }
        return re;
}

Leave Your Comment

Your email will not be published or shared. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="">

*
请输入图片中的字符以验证你并非垃圾机器人. 点击图片收听验证码的语音版.
点击这里收听此验证码的语音版本