window . showModalDialog(模式对话框,对话框创建后必须关闭后才能操作其他窗口) 和window.showModelessDialog(无模式对话框)
这种方式是将第一个页面的window对象传递给被引用页面,然后在被引用页面中操作第一个页面。
sURL | 必选项。字符串(String)。指定要载入和显示的 URL 。 | |||||||||||||||||||||||||||||||||||||
vArguments | 可选项。指定供显示文档时使用的变量。利用这个参数可以传递任何类型的值,包括包含多个值得的数组。对话框可以通过调用程序从 window对象的 dialogArguments属性提取这些值。 | |||||||||||||||||||||||||||||||||||||
sFeatures | 可选项。字符串(String)。指定对话框的窗口装饰。使用下面的值。多个之间用分号隔开。
|
a.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>a.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
<script type="text/javascript">
function selectKeHu(){
window.showModalDialog("b.html",window,"dialogHeight:10;dialogWidth:20");
}
function addValue(value){
document.getElementById("userName").value = value;
}
</script>
</head>
<body>
选择客户<input type="text" name="userName" οnclick="selectKeHu()" id="userName">
</body>
</html>
b.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>b.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
<script type="text/javascript">
function change(value){
//利用window的dialogArguments属性获取a.html中window.showModalDialog方法的第二个属性(可以是window对象,也可以是任意值)
var a = window.dialogArguments;
//a.document.getElementById("userName").value = value; 不推荐,不需要自己去写具体操作
a.addValue(value);//推荐,调用a.html里的函数
}
</script>
</head>
<body>
<table>
<tr>
<td>法师</td>
<td><input type="button" value="选择" οnclick="change('法师')"></td>
</tr>
<tr>
<td>萨满</td>
<td><input type="button" value="选择" οnclick="change('萨满')"></td>
</tr>
</table>
</body>
</html>