<select name="ifentries" id="ifentries${index}" onchange="gradeChange('ifentries0')">
<option value="true" ${item.ifentries == true ? 'selected' : ''}>是</option>
<option value="false" ${item.ifentries == false ? 'selected' : ''}>否</option>
</select>
function gradeChange(id) {
console.log(id)
let myselect = document.getElementById(id) // id
let sletctIndex = myselect.selectedIndex // 选中的option的index
let selectValue = myselect.options[sletctIndex].value
console.log(selectValue)
}
原生js 获取select下拉值
最新推荐文章于 2023-05-17 16:47:23 发布
本文介绍了一个HTML选择器的示例代码,该选择器通过JavaScript实现动态交互功能,包括如何获取用户的选择并进行响应。文章详细解释了如何使用getElementById方法来定位元素,并读取用户的选择值。
3万+

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



