JavaScript中颜色能不能作为赋值变量给颜色赋值?
function chan(id,f){ clo = document.getElementById(id).style.background; if(f=="on") document.getElementById(id).style.backgroundColor="yellow"; else if(f == "off") document.getElementById(id).style.backgroundColor = clo;}
最佳答案
clo = document.getElementById(id).style.background;
style上面的样式是只写的,也就是只能赋值,不能读取
document.getElementById(id).style.backgroundColor="yellow";
这句有用
document.getElementById(id).style.backgroundColor = clo;
这句无效
其他回答
其它网友回答:
clo = document.getElementById(id).style.background;
其它网友回答:
这句代码拿的是background与下面的backgroundColor属性不一致