天天看点

两个HTML 页面间的数据传递

<html>

<head >
    <meta charset="UTF-8">
    <title> 起始页面 </title>>
</head>

<body>
    <form action="page02.html" method="GET">
        用户名:<input name="username" type="text" SIZE="10"><br> 密&nbsp;&nbsp;码:
        <input name="password" type="password" SIZE="10"><br>
        <button type="submit">提交</button>&nbsp;&nbsp;
        <button type="reset">重置</button>
    </form>
</body>

</html>
           

 第二个页面:命名page02.html

<html>
<head >
    <meta charset="UTF-8">
    <title> 目标页面 </title>
    <script type="text/javascript">
        var url = document.URL;
        document.write("URL:" + url + "<br>");
        var strQuery = url.split("?")[1]
        document.write("查询字符串:" + strQuery + "<br>")
        document.write(" 解析查询字符串:" + " < br >")
        var conditions = strQuery.split(" & ")
        for (var i = 0; i < conditions.length; i++) {
            var pair = conditions[i].split("=")
            var key = pair[0];
            var value = pair[1];
            document.write(key + ":" + value + "<br>")
        }
    </script>
</head>

<body>
</body>

</html>
           

继续阅读