曲奇饼 发表于 2019-11-18 21:46:11

用 js动态获取select选中的option

demo代码:

<select id="test" name="">
<option value="1">text1</option>
<option value="2">text2</option>
</select>
通过原生js方法

1: 拿到select对象: var myselect=document.getElementById("test");
2: 拿到选中项的索引:var index=myselect.selectedIndex ; // selectedIndex代表的是你所选中项的index
3: 拿到选中项options的value: myselect.options.value;
4: 拿到选中项options的text: myselect.options.text;
页: [1]
查看完整版本: 用 js动态获取select选中的option