我正在尝试使用 if... else 语句并通过数组元素的值将值分配给变量 stateCode。有些东西不工作,也许阵列不正确。这是代码:
<!DOCTYPE html>
<html>
<head>
<title>if...else</title>
<script type="text/javascript">
function choices() {
var stateCode = document.getElementById("x").value;
var taxes = new Array(10; 7.5; 3.2);
if ("x" === "OR") {
document.writeln(taxes[0]);
} else if ("x" === "CA") {
document.writeln(taxes[1]);
} else if ("x" === "MO") {
document.writeln(taxes[2]);
}
}
</script>
</head>
<body>
<p>
<select id="x" onchange="choices(this.value);">
<option value = "">---Reset---</option>
<option value = "MO">MO</option>
<option value = "OR">OR</option>
<option value = "CA">CA</option>
</select>
</p>
</body>
</html>