codeLib之javaScript之父子窗口问题2

2.window.showModalDialog()

 

vReturnValue = window.showModalDialog(sURL [, vArguments] [, sFeatures])

     vArguments父窗口向子窗口传递参数;

     vReturnValue子窗口向父窗口传递数据。

父窗口html

<div id="popup_2" align="center"><hr>
	<fieldset><legend>window.showModalDialog()</legend>
		<p><label for="name_2">名字:</label> <input type="text" name="name_2"></p>
		<p><label for="age_2">年龄:</label> <input type="text" name="age_2"></p>
		<p><label for="sex_2">性别:</label> <input type="text" name="sex_2"></p>
		<p><label for="dep_2">部门:</label> <input type="text" name="dep_2"></p>
		<p><label for="pro_2">职位:</label> <input type="text" name="pro_2"></p>
	</fieldset>
	<input type="button" class="button" onclick="showUserDialog(2)" value="显示子窗口二">
</div>

父窗口js

var options = "location=no,menubar=no,resizable=no,scrollbars=yes,status=no,titlebar=yes,toolbar=no,left=200,top=200,height=300,width=400";
var dialogOptions = "dialogWidth:400px;dialogHeight:300px;dialogLeft:350px;dialogTop:150px;center:no;help:no;resizable:no;status:no;scroll:no";
var legends = ["window.open()","window.showModalDialog()","window.showModelessDialog()"];
var title = "";
var arg_2 = new Object();
function showUserDialog(flag){
    title = legends[flag - 1];
    switch (flag) {
        case 1:
                window.open("inner_1.html","_blank",options);
            break;
        case 2:
                arg_2.title = title;
                arg_2.name_2 = document.all.name_2.value;
                arg_2.age_2 = document.all.age_2.value;
                arg_2.sex_2 = document.all.sex_2.value;
                arg_2.dep_2 = document.all.dep_2.value;
                arg_2.pro_2 = document.all.pro_2.value;                
                var res_2 = window.showModalDialog("inner_2.html",arg_2,dialogOptions);
                if(typeof(res_2) == "object"){
                    document.all.name_2.value = res_2.name_2;
                    document.all.age_2.value = res_2.age_2;
                    document.all.sex_2.value = res_2.sex_2;
                    document.all.dep_2.value = res_2.dep_2;
                    document.all.pro_2.value = res_2.pro_2;
                }
            break;
        case 3:
                window.showModalDialog("inner_3.html",window,dialogOptions);
            break;            
        default:
            break;
    }
}

 子窗口html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<title>Insert title here</title>
		<script language="javascript" src="script/popupWindow.js"></script>
	</head>
	<body onload="init_2()">
		<div align="center">
			<fieldset>
				<script language="javascript">
					document.write("<legend>" + getTitle_2() + "</legend>");
				</script>
				<p><label for="name_2">名字:</label> <input type="text" name="name_2"></p>
				<p><label for="age_2">年龄:</label> <input type="text" name="age_2"></p>
				<p><label for="sex_2">性别:</label> <input type="text" name="sex_2"></p>
				<p><label for="dep_2">部门:</label> <input type="text" name="dep_2"></p>
				<p><label for="pro_2">职位:</label> <input type="text" name="pro_2"></p>
			</fieldset>
			<input type="button" value="提 交" onclick="handIn_2()" class="">
		</div>
	</body>
</html>

子窗口js

function init_2(){
	var inputArg = window.dialogArguments;
	document.all.name_2.value = inputArg.name_2;
	document.all.age_2.value = inputArg.age_2;
	document.all.sex_2.value = inputArg.sex_2;
	document.all.dep_2.value = inputArg.dep_2;
	document.all.pro_2.value = inputArg.pro_2;
}
function handIn_2(){
	var inputArg = new Object;
	inputArg.name_2 = document.all.name_2.value;
	inputArg.age_2 = document.all.age_2.value;
	inputArg.sex_2 = document.all.sex_2.value;
	inputArg.dep_2 = document.all.dep_2.value;
	inputArg.pro_2 = document.all.pro_2.value;
	window.returnValue = inputArg;
	window.close();
}
function getTitle_2(){
	var inputArg = window.dialogArguments;
	return inputArg.title;
}

 

你可能感兴趣的:(JavaScript,html)