1、關(guān)于使用的幾張表的說(shuō)明 (1)Module:模塊表,記錄模塊名稱(chēng)、編碼等模塊基本數(shù)據(jù)。
(2)Permissions:權(quán)限表,記錄所有模塊權(quán)限distinct之后的數(shù)據(jù)。
(3)ModulePermissions:模塊權(quán)限,記錄每個(gè)模塊對(duì)應(yīng)的權(quán)限,一個(gè)模塊可能存在多條數(shù)據(jù),每條表示該模塊的一個(gè)操作權(quán)限。
(4)Roles:角色表,記錄角色名稱(chēng)、編碼等角色基本數(shù)據(jù)。
(5)RolePermissions:角色權(quán)限表,記錄每個(gè)角色對(duì)應(yīng)的權(quán)限,一個(gè)角色可能存在多條數(shù)據(jù),每條數(shù)據(jù)表示該角色在某個(gè)模塊的一個(gè)操作權(quán)限;表中的數(shù)據(jù)其實(shí)記錄的是角色編碼跟ModulePermissions表中的主鍵對(duì)應(yīng),表ModulePermissions中特定主鍵的數(shù)據(jù)行就表示了某個(gè)模塊的一個(gè)操作權(quán)限。
(6)SUser:用戶(hù)表,記錄用戶(hù)名等用戶(hù)基本信息。
(7)UserRole:用戶(hù)角色表,記錄每個(gè)用戶(hù)對(duì)應(yīng)的角色,可以是多個(gè),但本例只設(shè)置對(duì)應(yīng)一個(gè),只要用戶(hù)具有了某個(gè)角色,那么該用戶(hù)就具有了和角色一樣的權(quán)限。
2、關(guān)于PowerDesigher :上一篇介紹了初次在數(shù)據(jù)庫(kù)生成表的過(guò)程,實(shí)際上還可以實(shí)現(xiàn)更新和逆向操作(根據(jù)數(shù)據(jù)庫(kù)中的表在PD中生成表模型)。
3、模擬數(shù)據(jù) (1)表Module
(2)表Permissions
(3)表ModulePermissions
4、角色分頁(yè)顯示和刪除 這里實(shí)現(xiàn)功能的代碼基本都是最初級(jí)的代碼,后面另一個(gè)版本會(huì)在架構(gòu)、UI、代碼等方面進(jìn)行較大的改進(jìn);另外這里的代碼純粹是演示,不會(huì)考慮注入、異常等方面的處理。
(1)分頁(yè)顯示數(shù)據(jù)直接使用GridView了
(2)在列表頁(yè)面可以全選本頁(yè)數(shù)據(jù)一次性刪除,全選/全取消使用JQuery實(shí)現(xiàn),選中時(shí)將值(這里是角色編碼)保存在一個(gè)隱藏域中,隱藏域中的值的格式:'值1','值2',...(數(shù)據(jù)庫(kù)中的RoleCode列的數(shù)據(jù)類(lèi)型是nvarchar);取消選中時(shí)將隱藏域中的值清空;單行CheckBox選中/取消時(shí),將當(dāng)前行的值追加到隱藏域的值或從隱藏域的值中移除當(dāng)前行的值 。刪除時(shí)先判斷隱藏域的值是否為空,如果為空提示”選中數(shù)據(jù)“,如果不為空提示”確定刪除嗎?“,確認(rèn)刪除后,根據(jù)隱藏域中的值構(gòu)造delete語(yǔ)句(使用in子句)將數(shù)據(jù)刪除。
(3)代碼 Index.aspx <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Index.aspx.cs" Inherits="Role_Index" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www./TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www./1999/xhtml"> <head> <title>角色管理</title> <script type="text/javascript" src="../Scripts/jquery-1.4.1.min.js"></script> <script type="text/javascript"> //全選/取消CheckBox function CheckAll(cbAllId) { var keys = $("#txtKeys").val("").val(); //遍歷頁(yè)面中所有CheckBox, //根據(jù)GridView頭中CheckBox的checked值設(shè)置所有CheckBox的checked值, //同時(shí),如果Header中CheckBox為選中則獲取所有其他CheckBox的值(角色編碼), //構(gòu)造:'值','值',...格式的字符串,方便in查詢(xún), //如果Header中CheckBox的Checked值為false則清空txtKeys中的值 $(":checkbox").each(function () { //設(shè)置當(dāng)前遍歷到的CheckBox的選中狀態(tài)跟“全選”CheckBox一樣 $(this).attr("checked", $("#cbAll").attr("checked")); //如果當(dāng)前CheckBox選中,將值追加到隱藏域的value var cbValue = "'" + $(this).val() + "',"; if ($("#cbAll").attr("checked") && $(this).attr("id") != "cbAll") { keys += cbValue; } }); $("#txtKeys").val(keys); } //單行選擇 function CheckRow(cb) { var keys = $("#txtKeys").val(); var cbValue = "'" + $(cb).val() + "',"; //移除 if (!$(cb).attr("checked")) { keys = keys.replace(cbValue, ""); } else if (keys.indexOf(cbValue) == -1) {//追加 keys += cbValue; } $("#txtKeys").val(keys); } //刪除時(shí)檢查是否選中任何記錄,如果是讓用戶(hù)確認(rèn)刪除操作 function ConfirmDel() { if ($("#txtKeys").val().length == 0) { alert("請(qǐng)先選擇要?jiǎng)h除的數(shù)據(jù)"); return false; } else { return confirm("確定要?jiǎng)h除選中的數(shù)據(jù)嗎?"); } } </script> </head> <body> <form id="form1" runat="server"> 請(qǐng)輸入角色名稱(chēng):<asp:TextBox ID="txtKeyword" runat="server" Width="301px"></asp:TextBox> <asp:Button ID="btnQuery" runat="server" Text="查詢(xún)" onclick="btnQuery_Click" /> <!--存儲(chǔ)選中項(xiàng)的值列表,以“,”間隔,刪除時(shí)直接取值構(gòu)造SQL--> <asp:HiddenField ID="txtKeys" runat="server" EnableViewState="false" /> <div> <asp:GridView ID="gvRole" runat="server" AutoGenerateColumns="False" EnableModelValidation="True" Width="100%" AllowPaging="True" DataKeyNames="RoleCode" OnPageIndexChanging="gvRole_PageIndexChanging" OnRowDataBound="gvRole_RowDataBound" PageSize="4" > <Columns> <asp:TemplateField> <HeaderTemplate> <input id="cbAll" type="checkbox" onclick="CheckAll();" /> </HeaderTemplate> <ItemTemplate> <input id="cbRow" value='<%#Eval("RoleCode") %>' type="checkbox" onclick="CheckRow(this);" /> </ItemTemplate> <ItemStyle Width="30px" /> </asp:TemplateField> <asp:BoundField HeaderText="序號(hào)" HeaderStyle-Width="50px" ItemStyle-Width="50px"> <HeaderStyle Width="50px"></HeaderStyle> <ItemStyle Width="50px"></ItemStyle> </asp:BoundField> <asp:BoundField DataField="RoleName" HeaderText="角色名稱(chēng)" /> <asp:BoundField DataField="RoleCode" HeaderText="角色編碼" /> <asp:HyperLinkField Text="編輯" HeaderStyle-Width="50px" ItemStyle-Width="50px" DataNavigateUrlFields="RoleCode,RoleName" DataNavigateUrlFormatString="Edit.aspx?RoleCode={0}&RoleName={1}"> <HeaderStyle Width="50px"></HeaderStyle> <ItemStyle Width="50px"></ItemStyle> </asp:HyperLinkField> </Columns> <EmptyDataTemplate> 沒(méi)有數(shù)據(jù)。 </EmptyDataTemplate> <PagerSettings Position="TopAndBottom" /> </asp:GridView> </div> <asp:HyperLink ID="hlNew" runat="server" NavigateUrl="~/Role/Edit.aspx">新增</asp:HyperLink> | <asp:LinkButton ID="lbDelete" runat="server" OnClientClick="return ConfirmDel();" onclick="lbDelete_Click">刪除</asp:LinkButton> </form> </body> </html>
說(shuō)明: $("#txtKeys") :JQuery得到ID為txtKeys的元素 $("#txtKeys").val() ;:獲得ID為txtKeys的元素的值 $("#txtKeys").val("");:設(shè)置ID為txtKeys的元素的值,這里是空字符串 $(":checkbox").each(function () { });:遍歷當(dāng)前文檔中CheckBox類(lèi)型的元素,并在function中進(jìn)行處理 $(this).attr("checked");:獲得當(dāng)前遍歷到的CheckBox的checked屬性的值 $(this).attr("checked", $("#cbAll").attr("checked"));:設(shè)置當(dāng)前CheckBox的選中狀態(tài)跟“全選”CheckBox一樣,實(shí)際上就是通過(guò)這種方式給當(dāng)前CheckBox的checked屬性 注意所有CheckBox都有客戶(hù)端onclick事件,觸發(fā)時(shí)會(huì)調(diào)用不同JavaScript函數(shù)執(zhí)行 用到的Web服務(wù)器控件:TextBox 、Button、HiddenField、GridView、HyperLink、LinkButton
Index.aspx.cs using System;
using System.Web.UI.WebControls; using System.Data; public partial class Role_Index : System.Web.UI.Page { private void BindRoles() { string keyWord = this.txtKeyword.Text.Trim(); string querySql = string.Format("select * from Roles where RoleVisible=1 and RoleName Like '%{0}%'", keyWord); SqlHelper dbHelper = new SqlHelper(); DataTable dtRole = new DataTable(); dbHelper.FillDataTable(querySql, dtRole); gvRole.DataSource = dtRole; gvRole.DataBind(); } protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { BindRoles(); } } //翻頁(yè) protected void gvRole_PageIndexChanging(object sender, GridViewPageEventArgs e) { gvRole.PageIndex = e.NewPageIndex; BindRoles(); } protected void gvRole_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { //行編號(hào) e.Row.Cells[1].Text = Convert.ToString(gvRole.PageSize * gvRole.PageIndex + e.Row.RowIndex + 1); } } //查詢(xún) protected void btnQuery_Click(object sender, EventArgs e) { BindRoles(); } //刪除 protected void lbDelete_Click(object sender, EventArgs e) { string keys = txtKeys.Value.Trim(); string deleteSql = string.Format("delete from Roles where RoleCode in ({0})", keys.TrimEnd(',')); SqlHelper dbHelper = new SqlHelper(); if (dbHelper.ExecuteNonQueryWithTran(deleteSql)) { BindRoles(); txtKeys.Value = ""; } else { ClientScript.RegisterStartupScript(this.GetType(),"Infomation", "alert('刪除失敗!');",true); } } } 說(shuō)明: SqlHelper:是數(shù)據(jù)訪問(wèn)類(lèi),包含一些方法提供對(duì)數(shù)據(jù)庫(kù)的訪問(wèn)和操作 ExecuteNonQueryWithTran:調(diào)用SqlCommand的ExecuteNonQuery方法執(zhí)行insert、update、delete語(yǔ)句,添加了事務(wù)處理
5、角色新增和修改 (1)新建角色 這兒的關(guān)鍵是綁定權(quán)限、全選或全取消及獲取選中項(xiàng)的值、構(gòu)造insert語(yǔ)句,先看一下頁(yè)面運(yùn)行后的結(jié)果
(1.1)綁定權(quán)限 使用兩個(gè)GridView嵌套,最外面的(gvParent)顯示頂級(jí)模塊名稱(chēng);嵌套在內(nèi)的(gvChild)在gvParent的RowDataBound中進(jìn)行數(shù)據(jù)綁定以顯示二級(jí)模塊名稱(chēng)(根據(jù)gvParent當(dāng)前行的模塊編碼Moudle表中查詢(xún)數(shù)據(jù); 在gvChild的RowDataBound中綁定權(quán)限復(fù)選框列表,數(shù)據(jù)根據(jù)gvChild當(dāng)前行的模塊編碼從下面視圖(V_ModulePermissions)中查詢(xún),這里的復(fù)選框用的是<input type="checkbox" />,首先跟權(quán)限的數(shù)量構(gòu)造CheckBox的html代碼字符串,然后用Label顯示出來(lái),由于Label在客戶(hù)端生成的代碼中將變?yōu)樗羞@些CheckBox的父元素,所以也方便將來(lái)實(shí)現(xiàn)單模塊的全選或者全取消,具體內(nèi)容看后面代碼。 視圖V_ModulePermissions:
SQL: SELECT dbo.Permissions.PermissionName, dbo.ModulePermissions.ModuleCode, dbo.ModulePermissions.PermissionCode, dbo.ModulePermissions.ID
FROM dbo.ModulePermissions INNER JOIN dbo.Permissions ON dbo.ModulePermissions.PermissionCode = dbo.Permissions.PermissionCode INNER JOIN dbo.Module ON dbo.ModulePermissions.ModuleCode = dbo.Module.ModuleCode WHERE (dbo.Module.ModuleVisible = 1) AND (dbo.Permissions.PermissionVisible = 1)
(1.2)全選或全取消及獲取選中項(xiàng)的值 每一個(gè)CheckBox的Click事件觸發(fā)時(shí)都會(huì)調(diào)用一個(gè)JavaScript函數(shù)執(zhí)行,這些函數(shù)不僅是完成選中或者取消選中,還要完成獲得并追加或移除相應(yīng)的CheckBox的值,最終構(gòu)造的字符串是這種格式:,1,,2,,3,,4,...,并存儲(chǔ)在隱藏域中。代碼后面附上 。
(1.3)構(gòu)造insert語(yǔ)句 獲取隱藏域的值進(jìn)行字符串替換和拆分,遍歷拆分出來(lái)的數(shù)據(jù),構(gòu)造insert語(yǔ)句,最后執(zhí)行。
(2)修改角色 關(guān)鍵是設(shè)置當(dāng)前角色已有權(quán)限項(xiàng)選中,先看頁(yè)面結(jié)果
這里的處理是根據(jù)URL參數(shù)RoleCode的值從視圖V_RolePermissions查詢(xún)?cè)摻巧乃袡?quán)限,然后構(gòu)造一個(gè)字符串,在構(gòu)造<input type="checkbox" />時(shí)判斷該字符串是否包含此權(quán)限的標(biāo)識(shí),如果包含,就添加 checked屬性。
SQL: SELECT dbo.V_ModulePermissions.ID, dbo.RolePermissions.RoleCode FROM dbo.V_ModulePermissions INNER JOIN dbo.RolePermissions ON dbo.V_ModulePermissions.ID = dbo.RolePermissions.ModulePermissionID
(3)新建、修改全部代碼 Edit.aspx <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Edit.aspx.cs" Inherits="Role_Edit" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www./TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www./1999/xhtml"> <head runat="server"> <title>編輯角色</title> <script type="text/javascript" src="../Scripts/jquery-1.4.1.min.js"></script> <script type="text/javascript"> //全部模塊全選或全取消 function cbAllCheck(obj) { $("#txtPermissions").val(""); $(":checkbox").each(function () { $(this).attr("checked", $(obj).attr("checked")); if ($(obj).attr("checked")) { if ($(this).val() != "on") { $("#txtPermissions").val($("#txtPermissions").val() + "," + $(this).val() + ","); } } }); } //當(dāng)前模塊全選或全取消 function cbModuleCheck(obj, cblID) { $("#" + cblID).find(":input").each(function () { $(this).attr("checked", $(obj).attr("checked")); if ($(obj).attr("checked")) { if ($("#txtPermissions").val().indexOf("," + $(this).val() + ",") == -1) { $("#txtPermissions").val($("#txtPermissions").val() + "," + $(this).val() + ","); } } else { $("#txtPermissions").val( $("#txtPermissions").val().replace("," + $(this).val() + ",", "")); } }); } //當(dāng)前權(quán)限選中或取消 function cbPermissionCheck(obj) { if ($(obj).attr("checked")) { $("#txtPermissions").val($("#txtPermissions").val() + "," + $(obj).val() + ","); } else { $("#txtPermissions").val( $("#txtPermissions").val().replace("," + $(obj).val() + ",", "")); } } </script> </head> <body> <form id="form1" runat="server"> <asp:HiddenField ID="txtPermissions" runat="server" /> <div> 角色名稱(chēng):<asp:TextBox ID="txtRoleName" runat="server"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtRoleName" Display="Dynamic" ErrorMessage="<---請(qǐng)?zhí)顚?xiě)角色名稱(chēng)"></asp:RequiredFieldValidator> </div> <div> 角色編碼:<asp:TextBox ID="txtRoleCode" runat="server"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtRoleCode" Display="Dynamic" ErrorMessage="<---請(qǐng)?zhí)顚?xiě)角色編碼"></asp:RequiredFieldValidator> </div> <div><input id="cbAll" type="checkbox" onclick="cbAllCheck(this)" />全選</div> <div> <asp:GridView runat="server" ID="gvParent" AutoGenerateColumns="False" EnableModelValidation="True" DataKeyNames="ModuleCode" ShowHeader="false" OnRowDataBound="gvParent_RowDataBound" Width="100%"> <Columns> <asp:TemplateField> <ItemTemplate> <asp:Label ID="lblTopModule" runat="server" Font-Bold="true" Text='<%# Eval("ModuleName") %>'></asp:Label> <br /> <asp:GridView runat="server" ID="gvChild" AutoGenerateColumns="False" EnableModelValidation="True" DataKeyNames="ModuleCode" ShowHeader="false" OnRowDataBound="gvChild_RowDataBound" Width="100%"> <Columns> <asp:TemplateField> <ItemTemplate> <asp:Label ID="lblMoudle" runat="server" Text='<%# Eval("ModuleName") %>'></asp:Label> <asp:CheckBox id="cbModule" runat="server"/>全選 <br /> <asp:Label ID="lblPermissions" runat="server"></asp:Label> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> </div> <div> <asp:Button ID="btnSubmit" runat="server" Text="提交" onclick="btnSubmit_Click" /> </div> </form> </body> </html>
Edit.aspx.cs using System;
using System.Web.UI.WebControls; using System.Data; using System.Text; public partial class Role_Edit : System.Web.UI.Page { private DataSet ds = new DataSet(); private StringBuilder RolePermission { get; set; } private void BindTopModule() { if (ds != null && ds.Tables.Count > 0) { //篩選頂級(jí)模塊 DataRow[] drs = ds.Tables[0].Select("ParentCode='0'"); //克隆表結(jié)構(gòu) DataTable dt = ds.Tables[0].Clone(); foreach (DataRow dr in drs) { dt.ImportRow(dr); } gvParent.DataSource = dt; gvParent.DataBind(); } } private void SetRolePermission() { string querySql = string.Format("select * from V_RolePermissions where RoleCode='{0}'", ViewState["RoleCode"]); DataTable dt = new DataTable(); SqlHelper helper = new SqlHelper(); helper.FillDataTable(querySql, dt); if (dt != null) { foreach (DataRow dr in dt.Rows) { RolePermission.Append("," + dr["ID"].ToString() + ","); } } } protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { txtRoleName.Text = Request.QueryString["RoleName"]; ViewState["RoleCode"] = txtRoleCode.Text = Request.QueryString["RoleCode"]; //修改時(shí)根據(jù)RoleCode獲得當(dāng)前Role的所有權(quán)限ID if (ViewState["RoleCode"]!=null) { RolePermission = new StringBuilder(); ; SetRolePermission(); txtPermissions.Value = RolePermission.ToString(); } SqlHelper helper = new SqlHelper(); String querySql = "select * from Module where ModuleVisible=1;select * from V_ModulePermissions"; helper.FillDataSet(querySql, ds) ; BindTopModule(); } } protected void gvParent_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { GridView gv = (GridView)e.Row.FindControl("gvChild"); if (ds != null && ds.Tables.Count > 0) { DataRow[] drs = ds.Tables[0].Select("ParentCode='" + gvParent.DataKeys[e.Row.RowIndex].Value + "'"); DataTable dt = ds.Tables[0].Clone(); foreach (DataRow dr in drs) { dt.ImportRow(dr); } gv.DataSource = dt; gv.DataBind(); } } } protected void gvChild_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { if (ds != null && ds.Tables.Count > 1) { Label lblPermissions = (Label)e.Row.FindControl("lblPermissions"); StringBuilder appendCheckBox = new StringBuilder(); DataRow[] drs = ds.Tables[1].Select("ModuleCode='" + ((GridView)sender).DataKeys[e.Row.RowIndex].Value + "'"); for (int index = 0; index < drs.Length;index++ ) { DataRow dr = drs[index]; appendCheckBox.Append( string.Format("<input type='checkbox' id='{0}' value='{1}' onclick='cbPermissionCheck(this)' {3} />{2} ", "cb" + e.Row.RowIndex.ToString("00") + index.ToString("00"), dr["ID"].ToString(), dr["PermissionName"].ToString(), RolePermission != null && RolePermission.ToString().IndexOf("," + dr["ID"].ToString() + ",") >= 0 ? "checked" : "" ) ); //(delegate(string id){return id==dr["id"].ToString();})>=0 } lblPermissions.Text = appendCheckBox.ToString(); ((CheckBox)e.Row.FindControl("cbModule")).Attributes.Add("onclick", "cbModuleCheck(this,'" + lblPermissions.ClientID+ "')"); } } } protected void btnSubmit_Click(object sender, EventArgs e) { if (IsValid) { string roleName = txtRoleName.Text.Trim(); string roleCode = txtRoleCode.Text.Trim(); string[] permissions = txtPermissions.Value .TrimStart(',') .TrimEnd(',') .Replace(",,", ",") .Split(','); StringBuilder appendSql = new StringBuilder(); if (ViewState["RoleCode"] != null) { appendSql.Append(string.Format("delete from RolePermissions where RoleCode='{0}';", ViewState["RoleCode"])); appendSql.Append(string.Format("update Roles set RoleCode='{0}',RoleName='{1}' where RoleCode='{2}'", roleCode, roleName, ViewState["RoleCode"])); } else { appendSql.Append(string.Format("insert into Roles(RoleCode,RoleName) values('{0}','{1}')", roleCode, roleName)); } foreach (string s in permissions) { if (!string.IsNullOrEmpty(s)) { appendSql.Append( string.Format(";insert into dbo.RolePermissions values('{0}',{1})", roleCode, s)); } } txtPermissions.Value = ""; //Response.Write(appendSql.ToString()); SqlHelper helper = new SqlHelper(); if (helper.ExecuteNonQueryWithTran(appendSql.ToString())) { Response.Redirect("../Redirect.html?Role/Index.aspx"); } else { ClientScript.RegisterStartupScript(this.GetType(), "Infomation", "alert('操作失敗!');", true); } } } }
(4)操作成功后的提示及頁(yè)面跳轉(zhuǎn)
Redirect.html 使用setInterval函數(shù)倒計(jì)時(shí) 獲取傳遞過(guò)來(lái)的路徑(傳遞的是相對(duì)路徑),倒計(jì)時(shí)到0秒時(shí),使用window.clearInterval(intervalId)清除setInterval事件,并指定window.location.href=路徑,使得由當(dāng)前頁(yè)跳轉(zhuǎn)到目的頁(yè) <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www./TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www./1999/xhtml"> <head> <title>繼續(xù)</title> <script type="text/javascript"> //秒數(shù) var count = 3; //setIntervalId var setIntervalId; var url = location.href; url = url.substring(url.indexOf("?") + 1, url.length); function Redirect() { var displayOjb = document.getElementById("showTime") if (count == 0) { //清除setInterval window.clearInterval(setIntervalId); displayOjb.innerHTML = "網(wǎng)頁(yè)正在自動(dòng)跳轉(zhuǎn)"; location.href = url; } else { displayOjb.innerHTML = "操作成功!" + count + "秒后網(wǎng)頁(yè)自動(dòng)跳轉(zhuǎn)。"; count--; } } setIntervalId = setInterval("Redirect()", 1000); </script> </head> <body> <div id="showTime"></div> </body> </html>
OK,到此全部完成,感覺(jué)說(shuō)的太多了,所以有些內(nèi)容沒(méi)介紹,看代碼吧。 |
|
來(lái)自: 昵稱(chēng)7019201 > 《asp.net》