C# ASP.NET 后台界面加载时调用前台JavaScript脚本:Attributes.Add()

C# ASP.NET 后台界面加载时调用前台JavaScript脚本:Attributes.Add()在前台用JS写的脚本方法,除了可以直接用在前台控件的属性中,还可以在后台运用。即在后台页面加载时,调用JS方法。语法格式有两种,如下: 1.第一种写法:控件ID名.Attributes.Add(“事件名称”,“JS方法”);如:一个按钮控件Button1.Attributes.Add(“onclick”,“returnconfirm(‘确认?’)”);

在前台用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”);  //等效的写法

原文链接

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/35821.html

(0)
编程小号编程小号

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注