你可以只替换其中一部分,比如这样,
if (a) {
this.style.borderColor ='blue';
this.style.color='blue';
this.style.backgroundColor ='blue'
} else {
this.style.borderColor ='red';
this.style.color='red';
this.style.backgroundColor ='red'
}

解决方案 »

  1.   

    to ohding(ding):
      也样的话,就把样式硬编码到了代码中了,这样做不好吧?
      

  2.   

    试试expression

    .class1 {
      font-style:italic;
      font-size:12;
      color:expression((1==1)?"red":"blue")
    }
      

  3.   

    是什么样的条件呢?!
    要是触发事件可以简单的写:
    <div class="class1" onmouseover="this.className='class2'" onmouseout="this.className='class1'">
      <!--
        代码
      -->
    </div>
      

  4.   

    如果class2,class1的区别只是字体颜色不同,那么其他相同的属性也要在这两个class定义中出现,如果class1和class2中的属性很多,或又有另外几种classn,那么为了一个不同的属性,而维护这些大量的属性,我觉得不科学。还有如果用this.style.color='blue'方式,那么颜色就硬编码进代码,也不合适。那有更好的方法吗?