首页 > 代码库 > js实现页面传值

js实现页面传值

今天做东西用到,在网上查到了这样的一种方法,学习学习:

来源:http://bbs.csdn.net/topics/310229114

 

Page1:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head>    <title>无标题页</title>    <script type="text/javascript">    function OpenWin()    {      window.open("father.htm","aa","","");    }    </script></head><body>    <input id="T1" type="text" />    <input id="Button1" type="button" value="提交" onclick="OpenWin();" /></body></html>

 

Page2:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head>    <title>无标题页</title>    <script type="text/javascript">    function ReturnVal()    {      window.opener.document.getElementById(T1).value=document.getElementById(Text1).value;      window.close();    }    </script></head><body>    <input id="Text1" type="text" />    <input id="Button1" type="button" value="关闭" onclick="ReturnVal();" /></body></html>

 

PS:

使用window.opener可以访问js的变量 :window.opener.变量名

 

 

-------------