展会信息港展会大全

JS父页面与子页面相互传值方法
来源:互联网   发布日期:2016-01-27 15:44:26   浏览:1356次  

导读:这篇文章主要介绍了使用JS在父页面和子页面间相互传值方法,子页面可以是window open弹出的,也可以是iframe框架中的页面,需要 的朋友可以参考下一、子页面是父页面通过window open弹出的情况子页面要向父页面传值 ...

这篇文章主要介绍了使用JS在父页面和子页面间相互传值方法,子页面可以是window.open弹出的,也可以是iframe框架中的页面,需要 的朋友可以参考下

一、子页面是父页面通过window.open弹出的情况

子页面要向父页面传值,只要在document前面加window.opener即可。

如:

1.父页面代码:

<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>

2.子页面代码:

<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>

二、子页面是iframe框架中的页面情况

子页面要向父页面传值,只要在document前面加parent即可。

1.父页面代码:

<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>

2.子页面代码

<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>

赞助本站

人工智能实验室

相关热词: 页面 父页面 子页面 JS

相关内容
AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港