作业帮 > 数学 > 作业

js 多个if else判断的问题,下面是错的 该怎么写呢 如果用elseif也不行 必须用到else

来源:学生作业帮 编辑:作业帮 分类:数学作业 时间:2024/05/11 13:34:40
js 多个if else判断的问题,下面是错的 该怎么写呢 如果用elseif也不行 必须用到else
if(objid.style.backgroundColor=="#996600"){\x05
\x05 objid.style.backgroundColor="#E8F1FF";\x05\x05
\x05}else{\x05
\x05\x05objid.style.backgroundColor="#996600";
\x05}
\x05if(objid.style.backgroundColor=="#ffff66"){\x05
\x05 objid.style.backgroundColor="#E8F1FF";\x05\x05
\x05}else{\x05
\x05\x05objid.style.backgroundColor="#ffff66";
\x05}
\x05if(objid.style.backgroundColor=="#33FFFF"){\x05
\x05 objid.style.backgroundColor="#E8F1FF";\x05\x05
\x05}else{\x05
\x05\x05objid.style.backgroundColor="#33FFFF";
\x05}
\x05if(objid.style.backgroundColor=="#00FF33"){\x05
\x05 objid.style.backgroundColor="#E8F1FF";\x05\x05
\x05}else{\x05
\x05\x05objid.style.backgroundColor="#00FF33";
\x05}
if(objid.style.backgroundColor=="#996600"){\x05
\x05 objid.style.backgroundColor="#E8F1FF";\x05\x05
\x05}else if(objid.style.backgroundColor=="#ffff66"){\x05
\x05 objid.style.backgroundColor="#E8F1FF";\x05\x05
\x05}else if(objid.style.backgroundColor=="#33FFFF"){\x05
\x05 objid.style.backgroundColor="#E8F1FF";\x05\x05
\x05}else if(objid.style.backgroundColor=="#00FF33"){\x05
\x05 objid.style.backgroundColor="#E8F1FF";\x05\x05
\x05}else{\x05
\x05\x05objid.style.backgroundColor="#996600";
\x05}
再问: 我想每次else不同的值
再答: 呵呵,你可以用随机数啊,当不满足这些指定情况的,就随机产生一个颜色,或者从颜色列表中选择一个
再问: 如果我就想返回这四个颜色,有其他办法吗?
再答: 随机选一个就行了