Javascript怎么在两个窗体之间传值
来源:互联网 发布:js删除input输入框 编辑:程序博客网 时间:2024/05/16 11:08
众所周知window.open() 函数可以用来打开一个新窗口,那么如何在子窗体中向父窗体传值呢,其实通过window.opener即可获取父窗体的引用。
如我们新建窗体FatherPage.htm:
XML-Code:
<script type="text/javascript">function OpenChildWindow(){ window.open('ChildPage.htm'); }</script><input type="text" id="txtInput" /><input type="button" value="OpenChild" onclick="OpenChildWindow()" />
然后在ChildPage.htm中即可通过window.opener来访问父窗体中的元素:
XML-Code:
<script type="text/javascript">function SetValue(){ window.opener.document.getElementById('txtInput').value =document.getElementById('txtInput').value; window.close();}</script><input type="text" id="txtInput" /><input type="button" value="SetFather" onclick="SetValue()" />
其实在打开子窗体的同时,我们也可以对子窗体的元素进行赋值,因为window.open函数同样会返回一个子窗体的引用,因此FatherPage.htm可以修改为:
XML-Code:
<script type="text/javascript">function OpenChildWindow(){ var child = window.open('ChildPage.htm'); child.document.getElementById('txtInput').value =document.getElementById('txtInput').value; }</script><input type="text" id="txtInput" /><input type="button" value="OpenChild" onclick="OpenChildWindow()" />
通过判断子窗体的引用是否为空,我们还可以控制使其只能打开一个子窗体:
XML-Code:
<script type="text/javascript">var childfunction OpenChildWindow(){ if(!child) child = window.open('ChildPage.htm'); child.document.getElementById('txtInput').value =document.getElementById('txtInput').value; }</script><input type="text" id="txtInput" /><input type="button" value="OpenChild" onclick="OpenChildWindow()" />
光这样还不够,当关闭子窗体时还必须对父窗体的child变量进行清空,否则打开子窗体后再关闭就无法再重新打开了:
XML-Code:
- Javascript怎么在两个窗体之间传值
- Javascript怎么在两个窗体之间传值
- Javascript怎么在两个窗体之间传值2-showModalDialog
- Javascript showModalDialog两个窗体之间传值
- Javascript showModalDialog两个窗体之间传值
- Javascript 两个窗体之间传值实现代码
- Javascript 两个窗体之间传值实现代码
- 两个窗体之间传值
- 两个winform窗体之间的传值
- MFC 两个窗体之间传值
- c# 两个窗体之间的传值
- MDI父窗体和子窗体之间怎么传值?
- showModalDialog在父窗体和子窗体之间传值
- winform 两个窗体之间来回传值/相互传值
- VB.Net 两个窗体之间的传值及修改
- C#中两个不同窗体之间的传值
- NetBeans中两个窗体之间如何传值
- C#两个窗体之间值通信
- 中国航母梦:曾有小学生拿压岁钱支援建航母
- Hibernate Core,Annotations,JPA,EJB四者的关系
- picture browser software
- 手机PCB板图
- Windows下SVN的备份方案
- Javascript怎么在两个窗体之间传值
- 愚人?,看小朋友怎么忽悠人~~
- 数据迁移中遇到的问题
- Head First C# 中文版 图文皆译 第七章 接口和抽象类 page296
- SVN完全备份,增量备份,库同步
- 来北京三年整。
- Linux下SVN的三种备份方式
- 3D Studio File Format (转)
- 设计模式之简单工厂模式