码迷,mamicode.com
首页 > 其他好文 > 详细

Attributes.Add()

时间:2016-03-09 16:02:43      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:

在前台用JS写的脚本方法,除了可以直接用在前台控件的属性中,还可以在后台运用。 即在后台页面加载时,调用JS方法。

语法格式有两种,

如下:

 1.第一种写法:控件ID名.Attributes.Add(“事件名称”,“JS方法”);

如:一个按钮控件Button1.Attributes.Add(“onclick”,“return confirm(‘确认?‘)”);

 

2.另一写法:控件ID名.Attributes["事件名称"]=“JS方法";

如:前台写了一个JS方法: function ISCheck(){。。。。。。}; Button1.Attributes[“onclick”]="ISCheck()";

 

编程实战:

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‘)");

//以上两种方法是等效的


this.txtBeginDate.Attributes["readonly"] = "true";     //在txtBeginDate中添加readonly为True的属性。

this.txtBeginDate.Attributes.Add("readonly", "true");  //等效的写法

Attributes.Add()

标签:

原文地址:http://www.cnblogs.com/hell-world/p/5258111.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!