通过ASPX code添加CSS类的背后 [英] Adding css class through aspx code behind

查看:151
本文介绍了通过ASPX code添加CSS类的背后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的aspx。如果我有HTML如下:

I am using aspx. If I have HTML as follows:

<div id="classMe"></div>

我希望通过code动态添加CSS类隐藏文件,即在Page_Load中。这可能吗?

I am hoping to dynamically add a css class through the code behind file, ie on Page_Load. Is it possible?

感谢codeRS。

推荐答案

如果您要添加的属性,包括类,你需要设置 =服务器在标签上。

If you want to add attributes, including the class, you need to set runat="server" on the tag.

    <div id="classMe" runat="server"></div>

然后在code-背后:

Then in the code-behind:

classMe.Attributes.Add("class", "some-class")

这篇关于通过ASPX code添加CSS类的背后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆