0

これを行う方法があるかどうか疑問に思っていました:

Web ページにフォームがあり、ユーザーがフォームを送信すると、ページは別の静的 HTML ページにリダイレクトされます。

サーバー コードを使用せずに、2 番目の HTML ページのデータを操作する方法はありますか?

ユーザーが送信したフォーム データを 2 ページ目に表示できますか?

もちろん、2 番目のページをロードするための Ajax コードではなく、ナビゲーションが必要です (これを使用すると、データを簡単に操作できます)。

4

4 に答える 4

2

with GET メソッドを使用して<form>、いくつかのクエリ パラメータを含む別の静的 HTML ページに移動し、JavaScript でそれらのパラメータを取得できます。

先頭ページ:

<form method="GET" action="page2.html">
    <input type="text" name="value1"/>
    <input type="text" name="value2"/>
    <input type="submit"/>
</form>

2 ページ目:

<script type="text/javascript">
function getParams() {
    function decode(s) {
        return decodeURIComponent(s).split(/\+/).join(" ");
    }

    var params = {};

    document.location.search.replace(
        /\??(?:([^=]+)=([^&]*)&?)/g,
        function () {
            params[decode(arguments[1])] = decode(arguments[2]);
        });

    return params;
}

var params = getParams();

alert("value1=" + params.value1);
alert("value2=" + params.value2);
// or massage the DOM with these values
</script>
于 2009-02-06T04:17:46.670 に答える