ShowModalDialog方法的参数传递研究
来源:互联网 发布:java正则表达式匹配点 编辑:程序博客网 时间:2024/05/16 09:21
利用vReturnValue = window.showModalDialog(sURL [, vArguments] [,sFeatures]),我们可以打开一个模态窗口,该窗口的优点是限制用户只能对当前的页面进行操作,而对其父页面不能进行操作,常用于向导或者信息获取页面。
利用其中的vArguments我们可以在父页面和弹出的页面中进行参数的传递,参数可以为自定义的对象,也可以传递父页面中任何一个控件的引用,这使得我们可以很容易的来操作父页面中的各个元素,使得参数的传递变得非常容易。
1. 自定义对象参数传递
我们可以定义一个javascript对象,然后定义各种自定义属性的值,然后可以将此对象传递到子页面中。如:
父页面sender.htm源代码为:
<html>
<script>
function show()
{
var person = new Object();
person.myName=myName.value;
person.age = age.value;
person.country = country.value;
window.showModalDialog("target.htm",person,"");
}
</script>
<body>
<table>
<tr>
<td>
name:</td>
<td>
<input id="myName"></td>
</tr>
<tr>
<td>
age:</td>
<td>
<input id="age"></td>
</tr>
<tr>
<td>
country:</td>
<td>
<input id="country"></td>
</tr>
</table>
<br>
<input type="button" value="open" onclick="show()">
</body>
</html>
弹出的子页面target.htm的源代码为:
<html>
<body>
<table>
<tr>
<td>
name:</td>
<td id="myName">
</td>
</tr>
<tr>
<td>
age:</td>
<td id="age">
</td>
</tr>
<tr>
<td>
country:</td>
<td id="country">
</td>
</tr>
</table>
</body>
<script>
var person = window.dialogArguments;
myName.innerText = person.myName;
age.innerText = person.age;
country.innerText = person.country;
</script>
</html>
上述的代码可以将父页面的信息封装成一个对象,然后将该对象传递给子页面。
2. 父页面元素传递
我们可以将父页面中元素对象的引用传递给子页面,通过该引用我们可以访问父页面中的该元素对象。
Sender.htm源代码:
<html>
<script>
function show()
{
window.showModalDialog("target.htm",infoDiv,"");
}
</script>
<body>
<div id="infoDiv">
<table id="infoTable">
<tr>
<td>
name:</td>
<td>
<input id="myName"></td>
</tr>
<tr>
<td>
age:</td>
<td>
<input id="age"></td>
</tr>
<tr>
<td>
country:</td>
<td>
<input id="country"></td>
</tr>
</table>
</div>
<br>
<input type="button" value="conveyElement" onclick="show()">
</body>
</html>
Target.htm源代码:
//其中利用元素对象的引用我们可以操纵父页面的元素对象的属性。
<html>
<body>
<div id="childDiv">
</div>
<script>
var infoDiv = window.dialogArguments;
</script>
<br>
<input type="button" value="showInnerHtml" onclick='childDiv.innerHTML=infoDiv.innerHTML'>
<br>
<input type="button" value="changePColor" onclick='infoDiv.style.backgroundColor="lightgreen"'>
</body>
</html>
- ShowModalDialog方法的参数传递研究
- ShowModalDialog方法的参数传递研究
- showModalDialog 传递参数
- js showModalDialog参数传递
- js showModalDialog参数传递
- window.showModalDialog参数传递
- 在showModalDialog中使用post方法传递参数
- showModalDialog传递多个参数
- window.showModalDialog()如何传递参数
- JS中showModalDialog参数传递
- EOS中showModalDialog的用法以及参数的传递
- 用window.showModalDialog传递任意长度的参数
- window.showModalDialog 与window.open传递参数的不同?
- window.showModalDialog 与window.open传递参数的不同?
- window.showModalDialog 参数传递中含有特殊字符的处理
- window.showModalDialog 与window.open传递参数的不同?
- window.showModalDialog 与window.open传递参数的不同?
- 参数传递的方法
- 从业15年,我对国内软件行业的评价
- linux 下的输出重定向
- 访问各种数据库代码
- 各类Java heap space 解决方法,并通过java代码获取JVM的相关信息,所在操作系统的信息(包含eclipse&myeclipse的调试的内存设置)
- inputstream和byte[]相互转换
- ShowModalDialog方法的参数传递研究
- 实例详解$_SERVER函数中QUERY_STRING和REQUEST_URI等四个变量区别
- Discovery 探索频道 -- 轮回的故事
- 微软大中华区CEO陈永正辞职信
- 生命的柠檬茶
- ROR汇集---Transaction
- 在ASP.NET AJAX Control Toolkit 1.0中使用GB2312的编码时出现乱码的两种解决方案
- 【转】Symbian内存泄露检查工具HookLogger安装及使用教程
- 十年总结(十):成为房奴,实习并兼职中