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除了可以是布尔值,还可以为整型、数组。