我試圖通過JavaScript操縱下拉列表,但我似乎每次得到這個代碼,我點擊一個按鈕:改變與按鈕單擊選擇選項下拉數據
TypeError: objDropDownMenu.options is undefined
objDropDownMenu.options[1].selected = true;
這裏是我的代碼:
<FORM NAME="myform" ACTION="" METHOD="GET">
<SELECT class="select diff_data" style="WIDTH: 165px" name=CarPick>
<OPTION value=1>Audi</OPTION>
<OPTION value=2>BMW</OPTION>
<OPTION value=3>Mercedes</OPTION>
</SELECT>
<INPUT TYPE="button" NAME="button2" Value="Write" onClick="writeText(this.form)">
</FORM>
<SCRIPT LANGUAGE="JavaScript">
var objDropDownMenu = document.getElementsByName("CarPick");
function writeText (form) {
objDropDownMenu.options[30].selected = true;
}
</SCRIPT>
Anyu想法爲什麼?謝謝!
「ProcStage」定義在哪裏? – epascarello
對不起,我忘了更改它在我的代碼:) – pufAmuf