本页内容为:弹出窗口并向父页面返回值的两种常用方法,该文章本站转载自网络,如有侵权请告之,我们将会及时将其删除,其正文内容如下:
方法一:使用showModalDialog方法
新建文件lyh.html
输入
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>来自Eric空间</title>
</head>
<body>
<input type="button" οnclick="show('lyhshow.html')" value="弹出窗口"><br><br><br>返回值:
<input type="text" id="returnvalue">
<script language="javascript">
function show(math)
{
var val= showModalDialog(math,"true", "dialogWidth:300px;dialogHeight:250px;status:no;help:no;");
if(!val)
{
return;
}
else
{
document.all.returnvalue.value=val;
}
}
</script>
</body>
</html>
新建文件lyhshow.html
输入
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>来自Eric空间</title>
</head>
<body>
请输入:<input type="text" id="txtValue" value=""><br><br><br>
<input type="button" οnclick="ReturnValue()" value="返回输入值">
<script language="javascript">
function ReturnValue()
{
window.returnValue=document.all.txtValue.value;
window.close();
}
</script>
</body>
</html>
方法二:用window.open弹出窗口
新建文件lyh2.html
输入
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>来自Eric空间</title>
</head>
<body>
<input type="button" οnclick="show('lyhshow2.html')" value="弹出窗口"><br><br><br>返回值:
<input type="text" id="returnvalue">
<script language="javascript">
<!--
function show(math)
{
window.open (math,'newwindow','height=250,width=300,top=300,left=300,toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no')
//写成一行
}
-->
</script>
</body>
</html>
新建文件lyhshow2.html
输入
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>来自Eric空间</title>
</head>
<body>
请输入:<input type="text" id="txtValue" value=""><br><br><br>
<input type="button" οnclick="ReturnValue()" value="返回输入值">
<script language="javascript">
function ReturnValue()
{
window.opener.document.all.returnvalue.value=document.all.txtValue.value;
window.close();
}
</script>
</body>
</html>