码迷,mamicode.com
首页 > 其他好文 > 详细

父页面与子页面间相互传值

时间:2017-09-13 19:26:01      阅读:119      评论:0      收藏:0      [点我收藏+]

标签:lang   set   ram   var   文档   inpu   alert   div   XML   

1。子页面又父页面通过window.open弹出 
子页面要向父页面传值,只要在document前面加window.opener即可。
如:
父页面:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<script language="javascript">
function tanchu()
{
window.open("Untitled-5.html");   
}
</script>
<body>
    <form id="form1" name="form1" method="post" action="">
        <label> <input type="submit" name="button" id="button" value="提交"
            onclick="tanchu()" />
        </label> <label> <input type="text" name="textfield" id="textfield" />
        </label>
    </form>
</body>
</html>

子页面

 
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<script language="javascript">
function aaa()
{
 window.opener.document.getElementByIdx(‘textfield‘).value=‘123123123‘;
}
</script>
<body>
    <form id="form1" name="form1" method="post" action="">
        <label> <input type="submit" name="button" id="button" value="提交"
            onclick="aaa()" />
        </label>
    </form>
</body>
</html>
 

2。子页面是iframe框架中的页面 子页面要向父页面传值,只要在document前面加parent即可。
父页面

 
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
    <form id="form1" name="form1" method="post" action="">
        <label> <input type="text" name="textfield" id="textfield" />
        </label>
        <iframe id="myiframe" src="Untitled-3.html"></iframe>
    </form>
</body>
</html>
 

子页面

 
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<script language="javascript">
function aa()
{ 
var a=parent.document.getElementByIdx(‘textfield‘).value;
alert(a); 
}
</script>
<body>
    <form id="form1" name="form1" method="post" action="">
        <label> <input type="submit" name="button" id="button" value="提交"
            onClick="aa()" />
        </label>
    </form>
</body>
</html>

父页面与子页面间相互传值

标签:lang   set   ram   var   文档   inpu   alert   div   XML   

原文地址:http://www.cnblogs.com/GotoJava/p/7516364.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!