网页编程中的模态对话框
調用代碼如下:
default.aspx
<%@ Page Language="C#" AutoEventWireup="true"? CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
??? <title></title>
??? <script type="text/javascript" language="javascript">
??????? function showChose() {
??????????? //以彈出窗口的形式 彈出頭像選擇窗口? 并接受返回值
??????????? var src = window.showModalDialog("Face.aspx", "", "width:480px;height:480px;menu:no;tool:no;status:no;");
??????????? //將返回的圖片 顯示出來
??????????? document.getElementById("imgFace").src = src;
??????? }
??? </script>
</head>
<body>
??? <form id="form1" runat="server">
??? <div>
??????? <!--用戶單擊此層 彈出頭像選擇窗口? -->
??????? <span style="color:Red;cursor:hand;" οnclick="showChose()">選擇頭像</span>
??????? <img id="imgFace" />
??? </div>
??? </form>
</body>
</html>
被調用頁面代碼如下:
face.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Face.aspx.cs" Inherits="Face" %>
<%@ Import Namespace="System.IO" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
??? <title></title>
??? <script type="text/javascript" language="javascript">
??????? //當用戶單擊頭像圖片時 執行的JavaScript腳本
??????? function returnFace(src) {
??????????? //關閉當前窗體? 并返回用戶選擇的頭像的URL
??????????? window.opener = "";
??????????? window.returnValue = src;
??????????? window.close();
??????? }
??? </script>
</head>
<body>
??? <form id="form1" runat="server">
??? <div>
??????? <%
???????????? //獲取頭像文件夾
??????????? DirectoryInfo dic = new DirectoryInfo(this.Server.MapPath("Faces"));
??????????? int i = 0;
??????????? //循環遍歷頭像文件
??????????? foreach (FileInfo f in dic.GetFiles())
??????????? {
??????????????? if (f.Extension == ".bmp")
??????????????? {
??????? %>
??????? <!---生成頭像顯示圖片框--->
??????? <img src='< ??????? <%
??????????? i++;
??????????? //每顯示10章圖片 即換行
??????????? if (i % 10 == 0)
??????????? {
??????????????? Response.Write("<br/>");
??????????? }
??????????? continue;
??????????????? }
??????????? }?????????
??????? %>
??? </div>
??? </form>
</body>
</html>
當不考慮效率時,或工期比較緊時,可考慮用這種方法。
?
?
總結
以上是生活随笔為你收集整理的网页编程中的模态对话框的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 浅谈:飞鸽传书 的TCP/IP原理
- 下一篇: C++动态数组(转)