我想在运行时中更改页面的CSS.如何实现这一目标. [英] I would like to change CSS of a page in Runtime. How to achieve this.
本文介绍了我想在运行时中更改页面的CSS.如何实现这一目标.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
目前,我正在页面中使用Style1.css.
但是我需要的是
在我的页面运行时..当用户单击按钮时,我需要将Style1.css更改为Style2.css
请帮助我....
Currently I''m Using Style1.css in my page..
but what i need is,
at the running time of my page.. when user clicks a button i need to change Style1.css to Style2.css
Plz help me....
推荐答案
如果您正在使用它们,请在page_preInIt事件中对其进行更改.或者,如果您只想更改css文件(不使用它们),请参考
在ASP.NET中动态设置指向CSS文件的链接 [
If you are using the them then change it in page_preInIt event. OR if you just want to change the css file (not using them ) then refer
Dynamically set a link to a CSS file in ASP.NET[^]
您可以使用Java脚本自动更改CSS
you can use java script it can automatically change css
<script type="text/javascript" language="javascript">
var myWidth = 0, myHeight = 0;
if( typeof( window.innerWidth ) == 'number' ) {
//Non-IE
myWidth = window.innerWidth;
myHeight = window.innerHeight;
} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
//IE 6+ in 'standards compliant mode'
myWidth = document.documentElement.clientWidth;
myHeight = document.documentElement.clientHeight;
} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
//IE 4 compatible
myWidth = document.body.clientWidth;
myHeight = document.body.clientHeight;
}
if (myWidth <=800)
{
document.write('<link href="App_Themes/Theme1/Css/Main800.css" rel="stylesheet" type="text/css" />');
}
if (myWidth <= 1024)
{
document.write('<link href="App_Themes/Theme1/Css/Main1024.css" rel="stylesheet" type="text/css" />');
}
if (myWidth >=1024)
{
document.write('<link rel="stylesheet" type="text/css" href="App_Themes/Theme1/Css/Main1280.css" />');
}
if (myWidth = 0) {
document.write('<link rel="stylesheet" type="text/css" href="App_Themes/Theme1/Css/Main1024.css" />');
}
</script>
看看这个
使用CSS并动态更改它们ASP.NET& C# [^ ]
免费附件
另外,您也可以使用主题.
ASP.NET 2.0中的主题和外观 [ ASP.NET 2.0(C#)中的动态主题 [
Look at this
Using CSS and Changing them Dynamically ASP.NET & C#[^]
Free attachments
Alternatively you can use Themes too.
Themes and Skins in ASP.NET 2.0[^]
Dynamic Themes in ASP.NET 2.0 (C#)[^]
这篇关于我想在运行时中更改页面的CSS.如何实现这一目标.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文