我正在尝试获取下拉框的值并继续获取错误Uncaught TypeError:无法读取属性'selectedIndex'为null。
继承我的代码:
JS
expirationYearSelectedIndex = document.getElementById("selYear").selectedIndex;
console.log("expirationYearSelectedIndex = " + expirationYearSelectedIndex);
expirationYear = document.getElementById("selYear").options[expirationYearSelectedIndex].value;
console.log("expirationYear = " + expirationYear);
HTML
<form action="">
<select id="SelYear" name="selYear">
<option selected value=""> Select a Major....</option>
<option value="Comptuer Information Systems"> CIS</option>
<option value="Math"> M</option>
<option value="CS"> CS</option>
<option value="History"> H</option>
</select>
</form>
答案 0 :(得分:1)
错过了ID <select id="SelYear" name="selYear">
document.getElementById("SelYear");