点击某一个页面中的按钮,弹出一个新页,在新页上操作结束后,返回一个值到父页面,这样的功能很多见,可以用很多种方法,但是代码比较多。如果用模式对话框会缩小代码量。
比如 这是父页面的一个按钮和一个文本框,按钮用来弹出子页,文本框用来接收值。
<
input
id
="Button1"
type
="button"
value
="button"
onclick
="doSelect()"
/>
< input type ="text" id ="te1" /></ td >
< input type ="text" id ="te1" /></ td >
父页面的js脚本
function
doSelect()
... {
strFeatures="dialogWidth=500px;dialogHeight=360px;center=yes;middle=yes ;help=no;status=no;scroll=no"; //弹出样式
var url,strReturn;
url="WebForm2.aspx"; //子页地址
strReturn=window.showModalDialog(url,'',strFeatures);
document.getElementById("te1").value=strReturn;
}
... {
strFeatures="dialogWidth=500px;dialogHeight=360px;center=yes;middle=yes ;help=no;status=no;scroll=no"; //弹出样式
var url,strReturn;
url="WebForm2.aspx"; //子页地址
strReturn=window.showModalDialog(url,'',strFeatures);
document.getElementById("te1").value=strReturn;
}
子页面包含一个按钮和一个文本框,按钮用来返回父页面,文本框用来输入给父页面传入的值
<
input
type
="text"
id
="te2"
/>
< input type ="button" id ="bt1" onclick ="okbtn_onclick()" style ="width: 61px" />
< input type ="button" id ="bt1" onclick ="okbtn_onclick()" style ="width: 61px" />
子页面脚本文件
function
okbtn_onclick()
... {
var commstr=document.getElementById("te2").value;
window.returnValue=commstr;
window.close() ;
}
... {
var commstr=document.getElementById("te2").value;
window.returnValue=commstr;
window.close() ;
}
代码不多,但是能实现上述功能,不做其它解释了。