1 <!DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd ">2 <HTML>3 <Head>4 <MetaCharSet= "UTF-8" />5 <!--meta http-equiv= "x-ua-compatible" content= "ie=7"/ - 6 <title>Css</title>7 <styletype= "Text/css">8 #div0{9 width:100px;Ten Height:100px; One background:Red; A } - </style> - the <Scripttype= "Text/javascript"> - window.onload= function(){ - varOdiv=document.getElementById ("Div0"); - + varsheet=document.stylesheets[0]; - varRuls=Sheet.cssrules||Sheet.rules; + varRule=ruls[0]; A alert (rule.selectortext); at alert (rule.style.cssText); - alert (rule.style.background); - - if(document.all) - { - Sheet.addrule ("#div0","Color:blue",0); in }Else - { to Sheet.insertrule ("#div0 {Color:orange}",0) + } - the * } $ </Script>Panax Notoginseng </Head> - <Body> the <DivID= "Div0">Div</Div> + </Body> A </HTML>
JavaScript manipulating CSS style sheets