- 需要添加change事件
- select元素.selectedIndex:获取选中索引号
- select元素.options[index].value:获取选择的值

<select id='select'>
<option value=”A”>第一个option</option>
<option value=”B”>第二个option</option>
</select>
<script>
var myselect = document.getElementById('select')
myselect.addEventListener('change', e => {
var index = myselect.selectedIndex
console.log(index);
console.log(myselect.options[index].value);
})
</script>
596

被折叠的 条评论
为什么被折叠?



