-2
程序唯一的問題是沒有選擇顏色,顏色總是黑色,我將單選按鈕更改爲單個文本輸入元素並且它工作,所以錯誤必須是相關的到單選按鈕。單選按鈕顏色選擇器
function hello() {
var name = document.getElementById("name").value;
var para = document.getElementById("para");
var myColor = "";
var color = {
green: document.getElementById("green"),
blue: document.getElementById("blue"),
red: document.getElementById("red")
}
switch (color) {
case color.green.checked:
myColor = "green";
break;
case color.blue.checked:
myColor = "blue";
break;
case color.red.checked:
myColor = "red";
default:
myColor = "black"
}
para.style.color = myColor;
if (name == "") {
para.innerHTML = "Incorrect Input";
} else {
para.innerHTML = "Hello " + name + "!";
}
}