模态对话框返回值问题?父页面无法获取子窗口返回值!请高手指点迷津,代码如下:
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>
解决方案 »
- JS如何得到后台CS中方法返回的值???????????
- discuz!nt 2.0 如何跟原来的系统整合
- windows2003,把补丁打全,IE7.树(微软提供的那个WEB树控件)上的onclick事件不响应。有谁知道为什么?
- 再开帖问同样的问题,高手进来帮看看错误!
- 关于获取上一页地址是参数无法正确传递的问题
- 如何判断弹出窗口被屏蔽如果屏蔽了 给出提示
- 请教高手:如何访问WebForm中的OCX控件的属性和方法???
- 菜鸟问题,如何减少asp.net页面的postback次数 100分
- 数据绑定问题!在线等待!
- 从BATA2到中文正式版遇到的问题
- 如何使用DataSet作为Report Servers报表的数据源?急~~
- 怎么样列出一篇文章的"相关文章"就像csdn一样?
(作者语:本来想用一问一答形式来写的,但是我想不出这个怎么问,所以只好这样了。)
这个东西比较麻烦,我改了好几次了不是没办法说明白(语文水平越来越差了),只好用个例子说明了。
例子:
现在需要在一个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")中可以对模态对话框就不行了吧~~~