<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<select id="oper_select">
<option value="+">+加</option>
<option value="-">-减</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
<script>
// 1.获取select下拉框
var myselect = document.getElementById("oper_select")
console.log(myselect)
// 2.获取option索引
var index = oper_select.selectedIndex
console.log(index)
//获取option的值
var oper_value = myselect.options[index].value
console.log(oper_value)
//选中option的文本
var oper_text = myselect.options[index].text
console.log(oper_text)
</script>
</body>
</html>
js获取select下拉框的option的值和文本
最新推荐文章于 2024-04-04 03:20:37 发布