读书人

弹出窗口返回值到父窗口的两个文本框

发布时间: 2011-12-20 22:26:40 作者: rapoo

弹出窗口返回值到父窗口的两个文本框?
子窗口返回值到父窗口的一个文本框用下面的方法:
//父窗口弹出方法
function openbm()
{
var returnValue=window.showModalDialog( 'bumen_father.aspx ', ' ', 'dialogHeight:352px;dialogWidth:566px;center:yes;help:no;status:no;scroll:yes ');


document.form1.Text1.value=returnValue;
}

//子窗口关闭事件
<script type= "text/javascript ">
function closewin()
{

var n =store.document.getElementById( 'ListBox1 ').selectedIndex;
if (n== '-1 ')
{
alert( '请右边框选择用户! ');
return false;
}else
{

document.form1.Hidden1.value=store.document.getElementById( 'ListBox1 ').options[n].text+ ', '+store.document.getElementById( 'ListBox1 ').options[n].value; //获取左框架的值


window.returnValue=document.form1.Hidden1.value;
window.close();
}
}
function canForm()
{
window.returnValue= ' ';
window.close(this);
}

</script>
但如果父窗口有两个文本框(如text1返回用户,text2返回id)又该如何?

[解决办法]
但如果父窗口有两个文本框(如text1返回用户,text2返回id)又该如何?
--------------------------------
方法比较多

1.
使用数组返回
// child.htm
window.returnValue = [myUserName, myUserId];
/* also
var arr = new Array();
arr[arr.length] = myUserName;
arr[arr.length] = myUserId;
window.returnValue = arr;
*/

// parent.htm
var retVal = window.showModalDialog(........
alert(retVal[0]);
alert(retVal[1]);

2.
使用对象,即时建立属性
// child.htm


window.returnValue = { "userName ": myUserName, "userId ": myUserId};
/* also
var o = new Object();
o.userName = myUserName;
o.userId = myUsreId;
window.returnValue = o;
*/

// parent.htm
var retVal = window.showModalDialog(........
alert(retVal.userName);
alert(retVal.userId);

3.
先拼接字符串,然后解析
// child.htm
window.returnValue = myUserName + ", " + myUserId;

// parent.htm
var retVal = window.showModalDialog(........
var arr = retVal.split( ', ');
alert(arr[0]);
alert(arr[0]);

4.
more unknown methods


Hope helpful!

读书人网 >asp.net

热点推荐