六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 178|回复: 0

ASP.NET 2.0 及其以后的版本中 CheckBox 控件的两个新属性

[复制链接]

升级  0.4%

326

主题

326

主题

326

主题

探花

Rank: 6Rank: 6

积分
1008
 楼主| 发表于 2013-2-7 20:43:52 | 显示全部楼层 |阅读模式
在ASP.NET 2.0及其以后的版本中, CheckBox 控件新增加了两个属性:InputAttributesLabelAttributes 。利用这两个属性,可以很方便地为label和input标签添加自定义属性,而使用 Attributes 则是不能完成这个任务的。不过,这个功能有些人还不知道,常被忽略。下面就是他们的使用方法:
<div style="padding-right: 5.4pt; padding-left: 5.4pt; background: rgb(230,230,230); padding-bottom: 4px; width: 95%; padding-top: 4px;"><%@ Page Language="C#" AutoEventWireup="true" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

  protected 
void Page_Load(object sender, EventArgs e)
  {
    CheckBox1.InputAttributes.Add(
"onmouseover""alert('I am input\'s mouseover 事件哦。')");
    CheckBox1.LabelAttributes.Add(
"onmouseover""alert('I am label\'s mouseover 事件哦。')");

  }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  
<title>孟宪会之测试</title>
</head>
<body>
  
<form id="form1" runat="server">
  
<asp:CheckBox ID="CheckBox1" runat="server" Text="选择项" />
  
</form>
</body>
</html>
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表