window.showModalDialog有三个参数,第一:子窗体地址url,第二:传给子窗体的参数,第三:窗体外观参数,(高,宽,居中等参数)
父窗体html:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ShowModalDialog.aspx.cs" Inherits="MyWebForm.ShowModalDialog" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script type="text/javascript" src="Scripts/jquery-1.10.2.min.js"></script>
<script type="text/javascript">
function ShowModialog() {
var city = $("#city").val();
/ /cityname 从子窗体返回来的值
var cityname = window.showModalDialog("XMLWebForm.aspx", { "cityname": city, "list": 110 }); // { "cityname": city, "list": 110 } 传给子窗体的参数以及值
$("#city").val(cityname);}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="button" value="模式窗口" οnclick="ShowModialog()" />
<input type="text" id="city" />
</div>
</form>
</body>
</html>
子窗体html:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="XMLWebForm.aspx.cs" Inherits="MyWebForm.XMLWebForm" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script src="Scripts/jquery-1.10.2.min.js"></script>
<script type="text/javascript">
$(function () {
$("#Close").click(function () {
var cityname = $("#province").text();
var city = window.dialogArguments.cityname; //获取从父窗体传过来的参数值
var list = window.dialogArguments.list;
window.returnValue = cityname; //返回父窗体的值
$("#getvalue").val(city + list);
window.close();//self.close();
})
})
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<select id="province">
<option value="001">郑州</option>
<option value="002">安阳</option>
<option value="003">新乡</option>
</select>
<input type="button" id="Close" value="Close" />
<input type="text" id="getvalue" />
</div>
</form>
</body>
</html>