我有以下javascript更改單擊輸入按鈕時選擇的值。點擊按鈕時,它將選擇項更改爲空白值。使用selectedIndex將值更改爲空白選擇
我試過.selectedIndex = '20'
和.selectedIndex = 20
,仍然得到空白結果。
<script type="text/javascript">
function changeDefault(){
document.getElementById('Skill_1').selectedIndex = '20';
}
</script>
<select id="Skill_1" name="Skill_1">
<option "selected" value="0" >Zero</option>
<option value="20" >Twenty</option>
<option value="40" >Forty</option>
</select>
<input type='button' onclick='changeDefault()' value='Set Defaults'/>
怎麼樣'。價值=「20'' – Vatev