你在 if(odiv.style.... 的上面插入一行:
alert(odiv.style.background);
你就知道为什么了。
我去问了一个前辈,他跟我说javascript读取到的是内联样式,gaibian()函数里,if条件里的odiv.style.background并没有读取到中.box {background: red;}里的red值,所以。。。。
你alert(odiv.style.background);
一下弹出的必然是rgb的颜色,所以你判断背景肯定不为 red 就走了else
把odiv.style.background写出来看看就知道了
这里可以用odivstyle.backgroundColor这样