1

example1.htmlからexample2.htmlに変数を渡すための次のコードがあります。ユーザー名とキーワードを使用してexample2.htmlに移動するためのwindow.location.hrefの構文はどうなりますか。

example1.html

<script type="text/javascript">
    var username = ($("#username").val());
    var keyword = ($("#keyword").val());

    $("#button1").click(function(){
         window.location.href = "http://localhost:2757/example2.html";
    });
</script>
4

1 に答える 1

5

クエリ文字列パラメータでそれらを渡したい場合は、次のようにすることができます。

window.location = "http://localhost:2757/example2.html?username=" + username + "&keyword=" + keyword;
于 2010-09-21T04:46:44.030 に答える