設置了一個顏色值,用十六進制顏色的時候一直執行else里面的顏色,等于沒有顏色閃爍,但是換成英文表示顏色,就可以實現顏色閃爍,想問下原因是什么?1.這是設置十六進制的顏色后,后臺一直打印2,并且顏色一直是紅色,等于文字沒有閃爍顏色.box{
??width:200px;
??height:200px;
??text-align:center;
??line-height:200px;
??border:1px?solid?#000;
?
}
#text{
?color:#f00;
}<p>會閃爍的文字</p>
<div?class="box">
??<p?id="text">今日特賣</p>
</div>var?text=document.getElementById("text");
function?ok(){
????console.log(text.style.color);
?if(text.style.color=="#f00"){
???text.style.color="#0f0";
???console.log(1);
?}else?{
???text.style.color="#f00";
???console.log(2);
?}
}
setInterval(ok,500);打印臺結果:2.這是顏色設置了英文表達后,實現了顏色閃爍的效果.box{
??width:200px;
??height:200px;
??text-align:center;
??line-height:200px;
??border:1px?solid?#000;
?
}
#text{
?color:red;
}<p>會閃爍的文字</p>
<div?class="box">
??<p?id="text">今日特賣</p>
</div>var?text=document.getElementById("text"),
????timer=null;
timer=setInterval(function?(){
?if(text.style.color=="red"){
???text.style.color="blue";
???console.log(1);
?}else{
???text.style.color="red";
???console.log(2);
?}
},500);打印臺結果:
js顏色閃爍問題
karsin
2018-04-17 17:42:56