我正在處理顯示與文本文件中指定的顏色匹配的彩色按鈕的代碼。不過,我面臨的一個問題是,只有第一個'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'。另外:***代碼格式化!! *** –