html dom获取option的值

html dom获取option的值
记录dom的学习经验。下次忘记的时候直接来拿

<select id="typevalue" onChange="modifyType();">

<option value="1" id="0">11</option>

<option value="2" id="1">22</option>

<option value="3" id="2">33</option>

<option value="4" id="3">44</option>

<option value="5" id="4">55</option>

<option value="6" id="5">66</option>

<option value="7" id="10">77</option>

</select>



获取选中的option的text值
var typevalue = document.getElementById("typevalue");
var typevalueText = typevalue.options[typevalue.selectedIndex].text;

获取选中的option的ID值
var typevalue = document.getElementById("typevalue");
var typevalueId = typevalue.options[typevalue.selectedIndex].id;

你可能感兴趣的:(html dom获取option的值)