我的 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/