Javascript怎么在两个窗体之间传值2-showModalDialog
来源:互联网 发布:数据分析会有什么风险 编辑:程序博客网 时间:2024/05/16 05:09
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:
<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:
<script type="text/javascript">function Load(){ document.getElementById('txtInput').value=window.dialogArguments[0] ;}</script>
同样我们还可以传递对象,如:FatherPage.htm:
<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:
<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:
<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:
<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怎么在两个窗体之间传值2-showModalDialog
- Javascript showModalDialog两个窗体之间传值
- Javascript showModalDialog两个窗体之间传值
- Javascript怎么在两个窗体之间传值
- Javascript怎么在两个窗体之间传值
- showModalDialog在父窗体和子窗体之间传值
- Javascript 两个窗体之间传值实现代码
- Javascript 两个窗体之间传值实现代码
- 两个窗体之间传值
- 两个窗体间的传值问题,模态(showModalDialog)窗口
- javascript关闭showmodalDialog窗体
- 两个winform窗体之间的传值
- MFC 两个窗体之间传值
- c# 两个窗体之间的传值
- MDI父窗体和子窗体之间怎么传值?
- JS的ShowModalDialog模式窗体传值
- winform 两个窗体之间来回传值/相互传值
- VB.Net 两个窗体之间的传值及修改
- 近之则不逊;慈不掌兵
- 给一个Action的result传多个参数
- vb中如何在任务管理器里面隐藏应用程序进程
- 你必须知道的C#的25个基础概念(附演示)
- 模拟桌面刷新代码
- Javascript怎么在两个窗体之间传值2-showModalDialog
- SQL生成GUID
- JVM 唯一,还是每个thread一个?有关 ThreadLocal 生成实例数量的困惑。
- 如何在登录到计算机之前运行批处理文件(转自微软)
- 迭代器模式(Iterator)
- BAT加密的几个小方法
- Gmail无法使用“添加附近”
- 由于“浏览”控件的样式太丑,想把他换成图片,但是出问题了!!!
- Linux下VLAN创建举例