方法一
将父页面中准备接收值的对象的ID传递到对话框窗口的子页面中,在子页面中直接操作该对象。
下面的例子中,每点击一次子页面中的button,父页面中的text中的值就会加1。
父页面a.html
Untitled
function test(){
window.showModalDialog(‘b.html’, counter,‘DialogHeight:100px;DialogWidth:100px;’);
}
子页面b.html
Untitled
function test(){
var ptextid = window.dialogArguments;
ptextid.value = parseInt(ptextid.value) + 1;
}
方法二
通过window.returnValue将子页面中的值传回父页面。
下面的例子中,将子页面中两个文本框中的数值相加并会传到父页面赋值到父页面的文本框中。
父页面a.html
<
Untitled
function test(){
var result = window.showModalDialog(‘b.html’,‘’,‘DialogHeight:100px;DialogWidth:100px;’);
if(result != undefined){
document.getElementById(‘result’).value = result;
}
}
子页面
function test(){
var add1 = document.getElementById(‘add1’).value;
var add2 = document.getElementById(‘add2’).value;
window.returnValue = parseInt(add1) + parseInt(add2);
window.close();
}
参数1:
参数2:
