How to pass javascript variables from one html pag

2019-02-20 15:21发布

I have the following code to pass variable from example1.html to example2.html , what will be the syntax in window.location.href to navigate to example2.html with username and keyword.

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>

1条回答
Evening l夕情丶
2楼-- · 2019-02-20 15:44

If you want to pass them by query string parameters you can do this:

window.location = "http://localhost:2757/example2.html?username=" + username + "&keyword=" + keyword;
查看更多
登录 后发表回答