语法格式有两种,编程
以下:this
1.第一种写法:控件ID名.Attributes.Add(“事件名称”,“JS方法”);事件
如:一个按钮控件Button1.Attributes.Add(“onclick”,“return confirm('确认?')”);io
2.另外一写法:控件ID名.Attributes["事件名称"]=“JS方法";function
如:前台写了一个JS方法: function ISCheck(){。。。。。。}; Button1.Attributes[“onclick”]="ISCheck()";class
编程实战:后台
this.txtBeginDate.Attributes["onclick"] = "return showCalendar('" + this.txtEmpName.ClientID + "','y/mm/dd')";
this.txtBeginDate.Attributes.Add("onclick", "return showCalendar('" + this.txtEmpName.ClientID + "','y/mm/dd')");cli
//以上两种方法是等效的语法
this.txtBeginDate.Attributes["readonly"] = "true"; //在txtBeginDate中添加readonly为True的属性。方法
this.txtBeginDate.Attributes.Add("readonly", "true"); //等效的写法