你可以只替换其中一部分,比如这样,
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'
}
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'
}
也样的话,就把样式硬编码到了代码中了,这样做不好吧?
如
.class1 {
font-style:italic;
font-size:12;
color:expression((1==1)?"red":"blue")
}
要是触发事件可以简单的写:
<div class="class1" onmouseover="this.className='class2'" onmouseout="this.className='class1'">
<!--
代码
-->
</div>