如何将javascript变量从一个html页面传递到其他html页面 [英] How to pass javascript variables from one html page to other html page
本文介绍了如何将javascript变量从一个html页面传递到其他html页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有下面的代码将example1.html中的变量传递给example2.html,window.location.href中的语法是什么,以用户名和关键字导航到example2.html。
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
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>
推荐答案
如果您想通过查询字符串参数传递它们,可以这样做:
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;
这篇关于如何将javascript变量从一个html页面传递到其他html页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文