手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >JS父页面与子页面相互传值方法
JS父页面与子页面相互传值方法
摘要:一、子页面是父页面通过window.open弹出的情况子页面要向父页面传值,只要在document前面加window.opener即可。如:...

一、子页面是父页面通过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="提交"

/>

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="提交"

/>

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="提交"

/>

label>

form>

</body>

</html>

【JS父页面与子页面相互传值方法】相关文章:

JavaScript中的pow()方法使用

js验证上传图片的方法

Javascipt中处理字符串之big()方法的使用

JavaScript中指定函数名称的相关方法

Javascript实现每日自动换一张图片的方法

jQuery实现页面内锚点平滑跳转特效的方法总结

JavaScript获取两个数组交集的方法

禁止按回车键提交表单的方法

Javascript实现广告页面的定时关闭

用JavaScript实现页面重定向功能的教程

精品推荐
分类导航