html如何两个页面之间相互传递数据

我现在有两个html页面,a.html,b.html;
我想把a.html中的表单form中的id和pwd传到b.html中,但是页面还出于a,html
请问a.html如何传,b.html如何接收传过来的数

1、使用表单传递数据

两个html页面,a.html,b.html想。把a.html中的表单form中的id和pwd传到b.html中

<form action="b.html" method="post" name="formName"></form>

要用form表单配合后台语言来传,发送类型POST和GET看你需求要换。

2、使用JS传递接收数据

<html1 ><input type="text" value="nihao" id="text"></html>

<html2></html>

如何用JS把HTML1中的text属性值nihao 传递给html2  在HTML2中有怎样用JS接收传递过来的数据并显示。

<html1><a href="html2.html?word=nihao"><a>
<html2>

js代码:

var str=location.href.search;//取地址参数部分
word = str.sbustr(str.indexOf('=')+1);


word就可以获得地址中传递的参数了;如果有多个参数可以用split函数

3、两个纯Html之间的传值实例

index1.htm页面

<HTML>
    <HEAD>
    <TITLE> New Document </TITLE>//标题
        <SCRIPT LANGUAGE="JavaScript"> //调用JavaScript方法   
        function show(){       
         var result = document.getElementByIdx("name").value;  //获取值.     
          location.href="index2.htm?name="+result;  //  链接跳转
                      }
        </SCRIPT>
          <style>.input7 {color: #999;width:145px;height:20px;border: 1px solid #CCCCCC; font-size:12px;background-color: #fff;}//css样式
          </style>
    </HEAD>
    <BODY>
    <input type="text" id="name" class="input7"><input type="button" value="OK" onclick="show()"/>//输出
    </BODY>
</HTML>


index2页面:

<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<SCRIPT LANGUAGE="JavaScript">
function getvalue(name){    
    var str=window.location.search;   //location.search是从当前URL的?号开始的字符串     
    if (str.indexOf(name)!=-1)//判断是否收到值
     {                
     var pos_start=str.indexOf(name)+name.length+1;  //解析获取值   
     var pos_end=str.indexOf("&",pos_start);        
     if (pos_end==-1){           
      alert( str.substring(pos_start));  //输出      
                      }
     else{           
      alert("没有此值~~");    
          }  
      }
</SCRIPT>
</HEAD>
<BODY>
<input type="button" onclick="getvalue('show')" value="GetValue"/>
</BODY>
</HTML>

温馨提示:答案为网友推荐,仅供参考
第1个回答  2017-07-29
如果是一个打开另一个,通过window.opener,如果有父级关系,window.parent,如果没关系,跨域名的,正常是需要有个服务器,来交互的,
第2个回答  2015-08-21
可以读写文件 或者 cookie来实现追问

能帮我写下代码么

第3个回答  2015-08-21
<form action="b.html" method="post" name="formName"></form>

要用form表单配合后台语言来传,发送类型POST和GET看你需求要换

本回答被网友采纳
相似回答