模态对话框返回值问题?父页面无法获取子窗口返回值!请高手指点迷津,代码如下:
1.WindowOpen.js// 产生一个模态对话框
function openDialog(obj,width,height)
{
showModalDialog(obj, window, "dialogWidth:"+width+"; dialogHeight:"+height+"; status:0; help:0");
}2.父窗体页面function ShowKeyword()
{
var str=openDialog("/Admin/Keyword/ShowKeywordsList.aspx","800px","400px");
if(str!=null)
{
document.getElementById("txtKey").value=str;
}
}
<input type="text" id="txtKey" onclick="ShowKeyword();" name="txtKey" style="width: 300px;" />3.子窗体页面<script language="javascript" type="text/javascript">
function GetCheckBoxValue()
{
var strCheckBoxValue="";
var arrInputs=document.getElementsByTagName('input');
for(i=0;i<arrInputs.length;i++)
{
if(arrInputs[i].type=='checkbox' && arrInputs[i].checked)
{
strCheckBoxValue+=arrInputs[i].value+";";
}
}
parent.window.returnValue=strCheckBoxValue.substring(0,strCheckBoxValue.lastIndexOf(";"));
window.close();
}
</script>
1.WindowOpen.js// 产生一个模态对话框
function openDialog(obj,width,height)
{
showModalDialog(obj, window, "dialogWidth:"+width+"; dialogHeight:"+height+"; status:0; help:0");
}2.父窗体页面function ShowKeyword()
{
var str=openDialog("/Admin/Keyword/ShowKeywordsList.aspx","800px","400px");
if(str!=null)
{
document.getElementById("txtKey").value=str;
}
}
<input type="text" id="txtKey" onclick="ShowKeyword();" name="txtKey" style="width: 300px;" />3.子窗体页面<script language="javascript" type="text/javascript">
function GetCheckBoxValue()
{
var strCheckBoxValue="";
var arrInputs=document.getElementsByTagName('input');
for(i=0;i<arrInputs.length;i++)
{
if(arrInputs[i].type=='checkbox' && arrInputs[i].checked)
{
strCheckBoxValue+=arrInputs[i].value+";";
}
}
parent.window.returnValue=strCheckBoxValue.substring(0,strCheckBoxValue.lastIndexOf(";"));
window.close();
}
</script>
(作者语:本来想用一问一答形式来写的,但是我想不出这个怎么问,所以只好这样了。)
这个东西比较麻烦,我改了好几次了不是没办法说明白(语文水平越来越差了),只好用个例子说明了。
例子:
现在需要在一个showModalDialog(或showModelessDialog)里读取或设置一个变量var_name 一般的传递方式:
window.showModalDialog("filename.htm",var_name)
//传递var_name变量
在showModalDialog(或showModelessDialog)读取和设置时:
alert(window.dialogArguments)//读取var_name变量
window.dialogArguments="oyiboy"//设置var_name变量
这种方式是可以满足的,但是当你想在操作var_name同时再操作第二个变理var_id时呢?就无法再进行操作了。这就是这种传递方式的局限性。
以下是我建议使用的传递方式:
window.showModalDialog("filename.htm",window)
//不管要操作什么变量,只直传递主窗口的window对象
在showModalDialog(或showModelessDialog)读取和设置时:
alert(window.dialogArguments.var_name)//读取var_name变量
window.dialogArguments.var_name="oyiboy"//设置var_name变量 同时我也可以操作var_id变量
alert(window.dialogArguments.var_id)//读取var_id变量
window.dialogArguments.var_id="001"//设置var_id变量 同样还可以对主窗口的任何对象进行操作,如form对象里的元素。
window.dialogArguments.form1.index1.value="这是在设置index1元素的值"
前面的parent不要
郁闷啊~~~~~
-----------------------
parent.window.returnValue
window.parent.returnValue
window.returnValue
这三种情况都返回不了值.提示:undefined
这个应该用在:window.open("default.html")中可以对模态对话框就不行了吧~~~