發布時間:2020-12-04 08:52 作者:獨孤劍 閱讀:1952
前臺代碼
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <asp:Button ID="Button1" runat="server" Text="隱藏" OnClick="Button1_Click" /> <asp:Button ID="Button2" runat="server" Text="顯示" OnClick="Button2_Click" /> <div id="container" runat="server"> 內容 </div> </form> </body> </html>
// 隱藏 protected void Button1_Click(object sender, EventArgs e) { //// 方式一 RegisterStartupScript("", "<script>document.getElementById('container').style.display='none';</script>"); // 方式二 Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>document.getElementById('container').style.display='none';</script>"); } // 顯示 protected void Button2_Click(object sender, EventArgs e) { // 方式一 RegisterStartupScript("", "<script>document.getElementById('container').style.display='';</script>"); // 方式二 Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>document.getElementById('container').style.display='';</script>"); }
微信打賞, 微信掃一掃
支付寶打賞, 支付寶掃一掃
如果文章對您有幫助,歡迎給作者打賞