background-color没有none值,用transparent设置无色
匿名 · 更新于 2013/12/17
其实这个例子是对一个CSS属性的理解:
<div style="background-color:transparent;">
<p>Mouse over this paragraph.</p>
</div>
<script type="text/javascript">
var x = document.getElementsByTagName_r('div');
function test(){
if(this.style.backgroundColor==''){
this.style.backgroundColor='#c00';}
else {this.style.backgroundColor=''}
}
for(i=0;i< x.length;i++){
}
</script>
我想:对一个元素点击然后,设置背景颜色,如果有颜色便设置为无,无便设置一个颜色.
关于这一点的判断,我开始if(this.style.backgroundColor=='none')
查看了一下CSS手册:
background-color:transparent;
background-color:#颜色值;或者是inherit