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>

 

上一篇:栈的实现


下一篇:C++11: condition_variable