window.returnValue的用法

        returnValue是javascript中html的window对象的属性,目的是返回窗口值,当用window.showModalDialog函数打开一个模态窗口时,用于返回窗口的值,下面举一个例子:

        先来看父窗口:

<html>
	<head>
		<script language="javascript">
			function showmodal(){
				var returnValue = window.showModalDialog("child.html",null,"dialogWidth:350px;dialogHeight:350px;help:no;status:no");
				
				if (returnValue){
					alert('子窗口返回真!');
				}else{
					alert('子窗口返回假!');
				}

			}
		</script>

		<title>这是父窗口</title>
	</head>
	<body>
		<input type="button" value="测试" οnclick="showmodal()" />
	</body>
</html>

        再来看子窗口:

<html>
	<head>
		<script language="javascript">
			function trans(tag){
				if (tag==0){
					window.returnValue=false;
				} else{
					window.returnValue=true;
				}

				window.close();	
			}
		</script>
		<title>这是子窗口</title>
	</head>
	<body>
		<input type="button" value="返回真" οnclick="trans(1)" >
		<input type="button" value="返回假" οnclick="trans(0)" >
	</body>
</html>

        这样一来,就可以实现从模态窗口向父窗口传递值的作用,就可以根据子窗口传递过来的值进行操作,而且returnValue除了可以是布尔值,还可以为整型、数组。

        

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 15
    评论
评论 15
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值