JS父窗体与子窗体之间互相传值

使用IE6.0以上运行以下两个.HTML文件格式(放在同一个文件目录下)(原创)
[b]father.html:[/b]
[color=green]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<BODY οnlοad="window.status='小波资源'">
<form name="form1" id="form1">
<center>
<font color="blue" size="5">get Son Window element value</font><br/>
<input type="text" name="test1" id="test1" value="111"/><br/>
<input type="text" name="test2" id="test2" value="222"/><br/>
<input type="text" name="test3" id="test3" value="333"/><br/>
<input type="text" name="test4" id="test4" value="getSonValue"/><br/>
<input type="button" name="button" id="button" value="TEST" οnclick="showModel()"/><br/>
</center>
</form>
</BODY>
</HTML>
<script language="javascript">
function showModel(){
var arrayObj=new Array(document.getElementById("test1").value,document.getElementById("test2").value,document.getElementById("test3").value);
var returnValue=window.showModalDialog("son.html",arrayObj,'dialogWidth:650px;dialogHeight:450px');
if(typeof(returnValue) != "undefined"){
document.all("test1").value=returnValue.t1;
document.all("test2").value=returnValue.t2;
document.all("test3").value=returnValue.t3;
document.all("test4").value=returnValue.t4;
if(returnValue!=null){
if(confirm("Are you refresh???"))
location.reload();//refresh father window.html
}
}
if(returnValue+""=="undefined"){
if(confirm("Are you refresh???"))
location.reload();//refresh father window.html
}
}
</script>[/color]
[color=blue]
[b]son.html[/b]


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<base target="_self">
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<BODY οnlοad="window.status='小波资源'">>
<form name="son" id="son">
<p align="right"><input type="button" name="refresh" id="refresh" value="refresh" οnclick="history.go(0);"/></p>
<p align="center">
<font color="red" size="8">I am another window!!!</font>
<br/>
<input tyep="text" name="t1" id="t1" value="aaa"/><br/>
<input tyep="text" name="t2" id="t2" value="bbb"/><br/>
<input tyep="text" name="t3" id="t3" value="ccc"/><br/>
<input tyep="text" name="t4" id="t4" value="++sonwindow++"/><br/>
<input tyep="text" name="get1" id="get1" value="getFatherValue1"/><br/>
<input tyep="text" name="get2" id="get2" value="getFatherValue2"/><br/>
<input tyep="text" name="get3" id="get3" value="getFatherValue3"/><br/>
</p>
<br/>
<div align="center">
<input type="button" name="getButton" id="getButton" value="getFatherWindowElementValue" οnclick="getValue();"/><br/>
<input type="button" name="close" id="close" value="closeSonWindow" οnclick="close1();"/><br/>
<input type="text" name="key" id="key" value="getKeyValue" onKeyPress="getKeyValue();" />
</div>
</form>
</BODY>
</HTML>
<script language="javascript">
//alert(document.all("t2").value);
//alert(parent.window.opener.document.getElementById("test1").value);
function getValue(){
var a=window.dialogArguments;
if(a!=null){
document.getElementById("get1").value=a[0];
document.getElementById("get2").value=a[1];
document.getElementById("get3").value=a[2];
}else{
alert("Need to open father window!!!");
}
}
function close1(){
var returnObj=new Object();
returnObj.t1=document.getElementById("t1").value;
returnObj.t2=document.getElementById("t2").value;
returnObj.t3=document.getElementById("t3").value;
returnObj.t4=document.getElementById("t4").value;
window.returnValue=returnObj;
alert("Close son window,and pass son window parameters to father window element!!");
window.opener=null;
window.close();
}
function getKeyValue(){
var key=event.keyCode;
alert("key==="+key);
}
</script>


[/color]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值