我如何可以通过从一个HTML页面中的值,另一个使用JavaScript? [英] How can I pass a value from one HTML page to another using JavaScript?

查看:152
本文介绍了我如何可以通过从一个HTML页面中的值,另一个使用JavaScript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的第一个HTML页面:

This is my first HTML page:

<!--first.html-->   
<html>
    <body>
    <div data-role="page" data-theme="a" data-url="first" id="first"> 
        <form id="form1" name="form2" action="checking.html">
        <input type="text" name="txtFileName" id="txtFileName"/>
       <!-- <button onClick="uploadFile();">Upload</button> -->
       <input type="hidden" name="hidden1" value="">
       <br><input type="submit"  value="Send me your name!"  onClick="submitform();"><br>
       </form>
       <script type="text/javascript">
       function submitform()
       {
         document.forms.form1.hidden1.value=1;
         alert("i am working");

        document.form1.submit();
       }
    </script>

        </div>
    </body>
</html>

这是我第二次的HTML页面:

This is my second HTML page:

<!-- second.html -->
<html>
    <head>
    </head>
    <body> 
<h1>Javascript call after page loaded</h1>

<script>
function getQueryVariable2(variable) { 
  var query = window.location.search.substring(1); 
  document.write(query);
  var vars = query.split("&"); 
  document.write("<br />");
  document.write(vars);

  for (var i=0;i<vars.length;i++) { 
    var pair = vars[i].split("="); 
    if (pair[0] == variable) { 
      return pair[1]; 
    }
  } 
} 


document.write("<br />txtFileName = " + getQueryVariable2("txtFileName"));
document.write("<br />hid1 = " + getQueryVariable2("hid1"));
</script>
hellllo
</body>

在这里,我想从first.html显示hidden1的内容。请建议对我有什么code,我应该用这个。

Here I want to display the contents of hidden1 from first.html. Please suggest to me what code I should use for this.

推荐答案

在HTML5中,你可以使用会话从页面传递对象到另一个对象:

in HTML5 you can use session to pass object from page to another:

1 - 创建一个sesison

1- create a sesison

sessionStorage.setItem('key', 'value');

2 - 读会话:

2- read session:

sessionStorage.getItem('key')

检查该<一href="http://demos.w3avenue.com/html5-unleashed-tips-tricks-and-techniques/sample-09-sessionstorage-demo.html">example

这篇关于我如何可以通过从一个HTML页面中的值,另一个使用JavaScript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆