如下,当c.style.backgroundColor=="red"时 我可以通过点击
已占用
在红色和蓝色之间切换div颜色
可是,一旦改为 if(c.style.backgroundColor=="#fd4d4f"){
c.style.backgroundColor="#1fe26d";
}else{
c.style.backgroundColor="#fd4d4f"
}
就无法切换了
<div class="info-box1 bg-fff" style="height: 135px;border:0;background-color: #fd4d4f;">
<p style="font-size: 25px;color: white;"><a title="信息" href="javascript:;"onclick="xiang('包厢信息','xiang.html','1','700','600')"><strong>101</strong></a></p>
<p style="font-size: 20px;color: white;">(8人)</p>
<hr style="color: white;">
<a style="text-decoration:none;">
<p style="font-size: 20px;color: white;padding-top: 15px;" class="test">
<Strong id="1" onclick="changeColor(this)">已占用</Strong>
</p>
</a>
</div>
function changeColor(obj) {
var a = obj.parentNode;
var b = a.parentNode;
var c = b.parentNode;
if(c.style.backgroundColor=="red"){ //判断,倘若为红色,则变绿
c.style.backgroundColor="blue";
}else{
c.style.backgroundColor="red"
}
}
转换成rgb
fd4d4f => rgb(253, 77, 79)
1fe26d=> rgb(31, 226, 109)