如何:在 ASP.NET 网页中设置控件的 HTML 属性

本文介绍了如何在网页中添加标准HTML属性、样式属性及通过属性添加方式改变按钮的外观和行为,包括添加点击事件、修改背景颜色和背景色。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<body id="body" runat="server">
    <form id="form1" runat="server">

      <!-- Example1 --> 
      <input runat="server" id="Button1" type="button" onmouseover="rollover()" onmouseout="exitrollover()" />
    </form>
</body>

<script runat="server">
    private void Page_Load()
    {
        //Example 2
        Button1.Attributes.Add("onclick", "alert('hello, world')");
        Button1.Style.Add("background-color", "red");
        
        //Example 3
        Button1.Attributes["bgcolor"] = "lightblue";
       
    }
</script>


        Button1.Attributes.Add("onclick", "alert('hello, world')");  //添加标准Html 属性
        Button1.Style.Add("background-color", "red");//向样式里面添加指定的样式属性
       
        //Example 3
        Button1.Attributes["bgcolor"] = "lightblue";//添加标准的Html属性
      

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值