c# - 使用 C# 代码 (ASP.net) 选择 CSS 样式

标签 c# html asp.net css

我的 Default.aspx 页面的嵌入式 CSS 中有两个类。如果需要,我可以将代码转移到外部 CSS。

我可以用 C# 编写代码,在单击按钮后,我可以在表格的两种样式之间进行选择吗? 我对 ASP 和 C# 还很陌生。

我的类(class)(嵌入式):

   .tftable
    {
        background-color: Blue;
        font-size: 12px;
        color: #333333;
        margin: 0px;
        padding: 0px;
        width: 100%;
        border-width: 1px;
        border-color: #729ea5;
        border-collapse: collapse;
    }

    .CSSTable
    {
        background-color: Gray;
        margin: 0px;
        padding: 0px;
        width: 100%; /*Fits the <div>*/
        box-shadow: 10px 10px 5px #888888;

    }

因此,在单击 1 个按钮后,我的表格类将选择“tftable”,而另一个按钮将选择“CSS”表格类。

问候

最佳答案

不是c#代码,是javascript代码

添加如下Id的样式链接

<link href="css/style1.css" type="text/css" rel="stylesheet" id="stylesheet" />

然后创建一个Javascript函数来更改Css文件

function changeStyle(name){
    if(name=='style1')
        document.getElementById('stylesheet').href='css/style1.css';
    else if(name=='style2')
        document.getElementById('stylesheet').href='css/style2.css';
    else if(name=='style3')
        document.getElementById('stylesheet').href='css/style3.css';
}

在你的按钮中调用该函数

<ul>
<li><a href="javascript:changeStyle('style1')">Style1</a></li>
<li><a href="javascript:changeStyle('style2')">Style2</a></li>
<li><a href="javascript:changeStyle('style3')">Style3</a></li>
</ul>

引用

http://www.qualitycodes.com/tipdemos/javascript/dynamic-css/ http://www.qualitycodes.com/tip/14/dynamically-choosingchanging-a-css-file.html

关于c# - 使用 C# 代码 (ASP.net) 选择 CSS 样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22500182/

相关文章:

c# - 如何获取登录的用户ID C#

c# - 如何在 Windows Phone 8 中解析 Json 数组内的图像?

jquery - 打开页面时自动展开 div

c# - 如何在 C# 中创建只读对象属性?

javascript - 将 URL 中的图像插入 Google 文档

javascript - contenteditable 更改事件

asp.net - 使用母版页asp.net时如何在文件夹中查找页面

c# - 当 OleDbCommand 不支持多个查询时,分号 (;) 的用途是什么

c# - 为什么我的数据类型在分配时从大端转换回小端?

c# - 将普通英语转换为 SQL