css中直接的style调用,用:
document.getElementById("main").style.backgroundColor;可以
如果是指定的class的Css格式的话, <div class="testClass">
abc
</div> <div id="testId">
abc
</div>.testClass{
background-color:red;
}.testId{
background-color:red;
}
我想问对于第二种使用ID指定的css样式,在JS中要怎么调用? 谢谢了。。

解决方案 »

  1.   

    document.getElementById("id").className = "classname";
      

  2.   

    #testId{
    background-color:red;
    }
      

  3.   

    .testId{
    background-color:red;
    }
    是这样的吧
    #testId{
    background-color:red;
    }
      

  4.   

    或者 document.getElementById("testId").className="testId"
      

  5.   

    document.getElementById("testId").className="testId"????
    问题那个就没有className啊..
    怎么调用??
      

  6.   

    你要调用,必须写成.xxxx{
    background-color:red;
    }document.getElementById("testId").className="xxxx"
      

  7.   

    class是关键字,在js中用className