我正在处理显示与文本文件中指定的颜色匹配的彩色按钮的代码。不过,我面临的一个问题是,只有第一个'if'在与条目匹配之后执行并且最后一个doesnt中指定的'if'条件完全被检查。 喜欢,如果指定的颜色是红色,蓝色。然后输出只显示红色的按钮。多个如果条件不起作用
这里是我的代码
if(R)
{
document.write('<button style="background-color:red;width:100;height:100" </button>');
}
else
if(V)
{
document.write('<button style="background-color:violet;width:100;height:100"
</button>'); }
else
if(I)
{
document.write('<button style="background-color:indigo;width:100;height:100"
</button>');
}
else
if(B)
{
document.write('<button style="background-color:blue;width:100;height:100"
</button>');
}
else
if(G)
{
document.write('<button style="background-color:green;width:100;height:100"
</button>');
}
else
if(Y)
{
document.write('<button style="background-color:yellow;width:100;height:100"
</button>');
}
else
if(O)
{
document.write('<button style="background-color:orange;width:100;height:100"
</button>');
}
这些变量的值是什么?你在控制台中遇到任何错误吗?你可以做一个'''FIDDLE'''吗? –
所以你假设javascript会为你猜'R','I','B'和'V'的含义?幸运的是,它还不能这样做(嗨,SkyNet) –
如果你想做多个不相关的测试,那么你根本不想使用'else'。另外:***代码格式化!! *** –