当前位置: 代码迷 >> ASP.NET >> [@100@],请帮小弟我改一下改变背景色的JS,小弟我初学,多谢了
  详细解决方案

[@100@],请帮小弟我改一下改变背景色的JS,小弟我初学,多谢了

热度:3812   发布时间:2013-02-25 00:00:00.0
[@100@],请帮我改一下改变背景色的JS,我初学,谢谢了。
一个test.aspx一个one.css和two.css

one.css中
body  
{
        background:#CCFFCC;
}
two.css
body  
{
        background:#000000;
}


test.aspx中
<html   xmlns= "http://www.w3.org/1999/xhtml "   >
<head   runat= "server ">
        <title> 无标题页 </title>
        <script   language=javascript>
        function   ChangeColor(i)
        {
        document.all.csss.href   =   "a.css ";  
        }
        </script>
</head>
<body>
        <form   id= "form1 "   runat= "server ">
        <div>
                <input   id= "Button1 "   type= "button "   value= "button "   onclick= "ChangeColor( 'one.css ') "/>
                <input   id= "Button2 "   type= "button "   value= "button "   onclick= "ChangeColor( 'two.css ') "/> </div>
        </form>
</body>
</html>

写到这不会写了,请高人帮我一下,想通过JS实现动态选择不同的CSS样式文件。谢谢了。在线,对了立即给分。


------解决方案--------------------------------------------------------
@LZ

好象也没有这个document.all.csss.href ??

LZ是要换肤吧,送你断代码

<HTML>
<HEAD>
<link ID= "skin " rel= "stylesheet " type= "text/css ">
<TITLE> 换肤技术 </TITLE>
<SCRIPT LANGUAGE=javascript>
<!--
function SetCookie(name,value){
var argv=SetCookie.arguments;
var argc=SetCookie.arguments.length;
var expires=(2 <argc)?argv[2]:null;
var path=(3 <argc)?argv[3]:null;
var domain=(4 <argc)?argv[4]:null;
var secure=(5 <argc)?argv[5]:false;
document.cookie=name+ "= "+escape(value)+((expires==null)? " ":( "; expires= "+expires.toGMTString()))+((path==null)? " ":( "; path= "+path))+((domain==null)? " ":( "; domain= "+domain))+((secure==true)? "; secure ": " ");
}

function GetCookie(Name) {
var search = Name + "= ";
var returnvalue = " ";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search);
if (offset != -1) {
offset += search.length;
end = document.cookie.indexOf( "; ", offset);
if (end == -1)
end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset,end));
}
}
return returnvalue;
}

var thisskin;
thisskin=GetCookie( "nowskin ");
if(thisskin!= " ")
skin.href=thisskin;
else
skin.href= "css.css ";

function changecss(url){
if(url!= " "){
skin.href=url;
var expdate=new Date();
expdate.setTime(expdate.getTime()+(24*60*60*1000*30));
//expdate=null;
//以下设置COOKIES时间为1年,自己随便设置该时间..
SetCookie( "nowskin ",url,expdate, "/ ",null,false);
}
}
//-->
</SCRIPT>
</HEAD>
<BODY>

<P> 请选择下面的下拉菜单测试换肤效果 </P>
  相关解决方案