javascript获取url上的参数

测试javascript获取url参数

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
        <script type="text/javascript">
               function getQueryVariable(variable) {
                   debugger;
                    var query = window.location.search.substring(1);
                    var vars = query.split("&");
                    for (var i = 0; i < vars.length; i++) {
                        var pair = vars[i].split("=");
                        if (pair[0] == variable) { return pair[1]; }
                    }
                    
                    return (false);
                }
                 function getParam(p){
                    var paramVal=getQueryVariable(p);
                    alert(paramVal);
                    
                 }
            
        </script>
    </head>
    <body>
        <input type="button" value="测试获取url参数"  onclick="getParam('name')" />
    </body>
    
</html>

 

posted on 2020-03-16 18:45  荆棘人  阅读(151)  评论(0编辑  收藏  举报

导航