Javascript 两个窗体之间传值实现代码
来源:互联网 发布:云计算概念龙头股 编辑:程序博客网 时间:2024/06/11 14:40
javascript中还有一个函数window.showModalDialog也可以打开一个新窗体,不过他打开的是一个模态窗口,那么如何在父窗体和子窗体之间传值呢?我们先看该函数的定义:vReturnValue = window.showModalDialog(sURL [, vArguments] [,sFeatures])
参数说明:
sURL–必选参数,类型:字符串。用来指定对话框要显示的文档的URL。
vArguments–可选参数,类型:变体。用来向对话框传递参数。传递的参数类型不限,包括数组等。对话框通过window.dialogArguments来取得传递进来的参数。
sFeatures–可选参数,类型:字符串。用来描述对话框的外观等信息,可以使用以下的一个或几个,用分号“;”隔开。
dialogHeight :对话框高度,不小于100px,IE4中dialogHeight 和 dialogWidth 默认的单位是em,而IE5中是px,为方便其见,在定义modal方式的对话框时,用px做单位。
dialogWidth: 对话框宽度。
dialogLeft: 离屏幕左的距离。
dialogTop: 离屏幕上的距离。
center: {yes | no | 1 | 0 }:窗口是否居中,默认yes,但仍可以指定高度和宽度。
help: {yes | no | 1 | 0 }:是否显示帮助按钮,默认yes。
resizable: {yes | no | 1 | 0 } [IE5+]:是否可被改变大小。默认no。
status: {yes | no | 1 | 0 } [IE5+]:是否显示状态栏。默认为yes[ Modeless]或no[Modal]。
scroll:{ yes | no | 1 | 0 | on | off }:指明对话框是否显示滚动条。默认为yes。
如:”dialogWidth=200px;dialogHeight=100px”
因此我们可以通过window.dialogArguments参数来在两个窗体之间传值
如下面两个页面:FatherPage.htm:
<script type="text/javascript"> function OpenChildWindow() { window.showModalDialog('ChildPage.htm',document.getElementById('txtInput').value); } </script> <input type="text" id="txtInput" /> <input type="button" value="OpenChild" onclick="OpenChildWindow()" />
ChildPage.htm:
<body onload="Load()"> <script type="text/javascript"> function Load() { document.getElementById('txtInput').value=window.dialogArguments ; } </script> <input type="text" id="txtInput" /> </body>
上面只是传递简单的字符串,我们还可以传递数组,如:FatherPage.htm:
XML-Code:
<script type="text/javascript"> function OpenChildWindow() { var args = new Array(); args[0] = document.getElementById('txtInput').value; window.showModalDialog('ChildPage.htm',args); } </script> <input type="text" id="txtInput" /> <input type="button" value="OpenChild" onclick="OpenChildWindow()" />ChildPage.htm: XML-Code: <script type="text/javascript"> function Load() { document.getElementById('txtInput').value=window.dialogArguments[0] ; } </script>
同样我们还可以传递对象,如:FatherPage.htm:
XML-Code:
<script type="text/javascript"> function OpenChildWindow() { var obj = new Object(); obj.name = document.getElementById('txtInput').value; window.showModalDialog('ChildPage.htm',obj); } </script> <input type="text" id="txtInput" /> <input type="button" value="OpenChild" onclick="OpenChildWindow()" />
ChildPage.html:
XML-Code:
<script type="text/javascript"> function Load() { var obj = window.dialogArguments; document.getElementById('txtInput').value=obj.name ; } </script>
以上都是从父窗体向子窗体传值,那么如何从子窗体向父窗体传值呢 ?其实通过window.returnValue就可以获取子窗体的值,window.returnValue与window.dialogArguments一样,可以是任意变量,包括字符串,数组,对象等。如:FatherPage.html:
XML-Code:
<script type="text/javascript"> function OpenChildWindow() { var obj = new Object(); obj.name = document.getElementById('txtInput').value; var result = window.showModalDialog('ChildPage.htm',obj); document.getElementById('txtInput').value = result.name; } </script> <input type="text" id="txtInput" /> <input type="button" value="OpenChild" onclick="OpenChildWindow()" />
ChildPage.html:
XML-Code:
<body onload="Load()"> <script type="text/javascript"> function Load() { var obj = window.dialogArguments; document.getElementById('txtInput').value=obj.name ; } function SetValue() { var obj = new Object(); obj.name = document.getElementById('txtInput').value; window.returnValue = obj; window.close(); } </script> <input type="text" id="txtInput" /> <input type="button" value="SetFather" onclick="SetValue()" /> </body>
- Javascript 两个窗体之间传值实现代码
- Javascript 两个窗体之间传值实现代码
- Javascript showModalDialog两个窗体之间传值
- Javascript showModalDialog两个窗体之间传值
- Javascript怎么在两个窗体之间传值
- Javascript怎么在两个窗体之间传值
- Javascript怎么在两个窗体之间传值2-showModalDialog
- 两个窗体之间传值
- 两个winform窗体之间的传值
- MFC 两个窗体之间传值
- c# 两个窗体之间的传值
- winform 两个窗体之间来回传值/相互传值
- VB.Net 两个窗体之间的传值及修改
- C#中两个不同窗体之间的传值
- NetBeans中两个窗体之间如何传值
- C#两个窗体之间值通信
- Winform中利用委托实现窗体之间的传值
- Winform中利用委托实现窗体之间的传值
- 二叉树的基本操作
- python彩色图转化为灰度图
- ARM微处理器第一弹:工作状态,存储器格式,指令长度,工作模式
- [leetcode: Python]237. Delete Node in a Linked List
- 【start from zero】java基础归纳【2】
- Javascript 两个窗体之间传值实现代码
- 设计模式六大原则之二:里氏替换原则
- wince应用程序自启动最简便的方法
- 欢迎使用CSDN-markdown编辑器
- 程序员的养成第二篇
- 根据二叉树的前序和中序建树
- 数据分析京东笔记本电脑
- (7)关卡编辑器之视口的操作
- JAVA语言ArrayList类使用实例详解