showModalDialog基本操作:父子窗口互传参数

ShowModalDialog基本操作:父子窗口互传参数

父窗口代码:

Copy to Clipboard Liehuo.Net Codes引用的内容: [www.veryhuo.com]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
<title>父窗口</title> 
</head> 
<body> 
<script type="text/javascript"> 
function onOpenWindow(){ 
//showModalDialog的第二个参数是传递给子窗口的值 
//在子窗口可以通过window.dialogArguments方法获取 
//如果不需要传递,这个参数就用window本身 
var obj = document.getElementById("rtnValue").value; 
var result = window.showModalDialog("window.htm",obj,"dialogWidth:500px;dialogHeight:400px"); 
if(result != null){ 
var name = result[0]; 
document.getElementById("rtnValue").value = name; 
}} 
</script> 
<input name="rtnValue" type="text" id="rtnValue" value="" /> 
<input type="submit" name="Submit" value="打开子窗口" οnclick='onOpenWindow()' /> 
</body> 
</html>

子窗口代码:

Copy to Clipboard Liehuo.Net Codes引用的内容: [www.veryhuo.com]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
<title>子窗口</title> 
</head> 
<body> 
请输入要返回的值: <input name="txtName" type="text" id="txtName" /> 
<input type="submit" name="Submit" value="确定" οnclick='onOK();' /> 
<script type="text/javascript"> 
document.getElementById("txtName").value = window.dialogArguments;function onOK(){ 
var runValue=new Array; 
runValue[0]=document.getElementById("txtName").value; 
window.returnValue = runValue; window.close();} 
</script> 
</body> 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值