結合如何此javascript,因爲我有選擇的檔次-11和品位-12的工作沒有工作,但只有BSCS由用戶挑選時的問題謝謝大家幫忙結合如何平變化在JavaScript
document.getElementById('course').onchange = function() {
if (["BSCS", "BSIT","BSHRM","BSBM","BSTM"].indexOf(this.value) > -1) {
document.getElementById("grade-11").setAttribute("disabled", true);
document.getElementById("grade-12").setAttribute("disabled", true);
}
else {
document.getElementById("grade-11").removeAttribute("disabled");
document.getElementById("grade-12").removeAttribute("disabled");
}
}
document.getElementById('course').onchange = function() {
if (["STEM", "TOP","GAS","HUMSS"].indexOf(this.value) > -1) {
document.getElementById("first-year").setAttribute("disabled", true);
document.getElementById("second-year").setAttribute("disabled", true);
document.getElementById("third-year").setAttribute("disabled", true);
document.getElementById("fourth-year").setAttribute("disabled", true);
} else {
document.getElementById("first-year").removeAttribute("disabled");
document.getElementById("second-year").removeAttribute("disabled");
document.getElementById("third-year").removeAttribute("disabled");
document.getElementById("fourth-year").removeAttribute("disabled");
}
}
右鍵,你設置'的document.getElementById(「當然」)onchange'是一兩件事,那麼你將它設置爲別的,覆蓋第一。您可以使用'element.addEventListener'來添加多個事件偵聽器,或者您可以將兩個onchange函數中的代碼合併爲一個函數。 – James