Attributes

 

  confirm() 方法用于显示一个带有指定消息和 OK 及取消按钮的对话框。

Attributes是指是属性的集合,位于using Systems.Web.UI.HtmlControls下,用于获取在ASP.NET页内的服务器空间标记上表示的所有属性名称和值对的集合。

 

<form id="form1" runat="server">
    <div>
    <asp:Button ID="Button1" runat="server" Text="Button1" OnClick="Button1_Click"/>
    </div>
    </form>

 

 protected void Button1_Click(object sender, EventArgs e)
    {
        Button1.Attributes.Add("onclick","confirm('1')"); //添加一对儿属性,名值对
        Button1.Attributes.Remove("onclick");//什么效果都没有,因为移除这个属性的名字,自动的也就移除了值
        Button1.Attributes.Add("onclick", "confirm('2')");
    }

 

 实验证明如果把名换为别的名字就是不好使的但不知道为什么

 

posted @ 2018-04-30 14:24  太阳上来回蹦跶  阅读(566)  评论(0编辑  收藏  举报