窗口间传递参数学习一
一.新建页面a.html
<html>
<head>
<title>传递参数</title>
<script type="text/javascript">
function Test()
{
var f;
f = form1.elements;
var obj = new Object();
obj.name = f.txtName.value;
obj.sex = f.txtSex.value;
// 将对象obj传递到模式窗口b.html
window.showModalDialog("b.html", obj, "dialogWidth:200px; dialogHeight:120px; help:0;");
}
</script>
</head>
<body>
<input id="Button1" type="button" value="传递参数" onclick="Test()" />
<form id="form1">
Name:<input type="text" id="txtName" value="张三" />
<br/>
Sex:<input type="text" id="txtSex" value="男" />
</form>
</body>
</html>
二.新建页面b.html
<html>
<head>
<title>显示参数</title>
<script type="text/javascript">
var obj = window.dialogArguments;
var name = obj.name;
var sex = obj.sex;
</script>
</head>
<body>
Name:
<script type="text/javascript">
document.write(name);
</script>
<br />
sex
<script type="text/javascript">
document.write(sex);
</script>
</body>
</html>
二.运行结果如下