1、由于模态窗体只有IE浏览器支持,因此,模态窗体的应用范围并不是很广泛,只需要了解即可。
modal.jsp:
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
<script>
function openModal() {
var obj222 = new Object();
obj222.p123 = document.getElementById("txt123").value;
obj222.p456 = document.getElementById("txt456").value;
obj555 = window.showModalDialog("example.jsp",obj222);
alert("已经从模态窗体中返回来了。。。。");
document.getElementById("txt123").value = obj555.p789;
document.getElementById("txt456").value = obj555.p78;
}
</script>
</head>
<body>
账号:<input type="text" id="txt123"/>
密码:<input type="text" id="txt456"/>
<input type="button" value="打开模态窗体" onclick="openModal()"/>
</body>
</html>
2、模态窗体的代码如下:
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
<script type="text/javascript">
function receive555(){
var obj333 = window.dialogArguments;
document.getElementById("txt001").value=obj333.p123;
document.getElementById("txt002").value=obj333.p456;
}
function returnBack() {
var obj444 = new Object();
obj444.p789 = document.getElementById("txt001").value;
obj444.p78 = document.getElementById("txt002").value;
window.returnValue = obj444;
window.close();
}
</script>
</head>
<body onload="receive555()">
<br />
<input type="text" id="txt001"/>
<br /><input type="text" id="txt002"/>
<br /><input type="button" value="返回模态窗体中的数据到原来的窗体中" onclick="returnBack()"/>
</body>
</html>