js如何通过类名 获得selece下拉框的值
- 作者: 熊宝121
- 来源: 51数据库
- 2021-07-03
通过ID获得下拉框的值: 1 用户类型: 2 <select name="type" id="userType"> 3 <option value="0">请选择</option> 4 <option value="1">普通类型</option> 5 <option value="2">VIP类型</option> 6</select>
1 var myType = document.getElementById("userType");//获取select对象
2 var index = myType.selectedIndex; //获取选项中的索引,selectIndex表示的是当前所选中的index
3 myType.options[index].value;//获取选项中options的value值
4 myType.options[index].text;//获取选项中options的value值
?
通过类名获得下拉框的值:
var value1_obj= document.getElementsByClassName("value1");//获取select对象
var index = value1_obj[0].selectedIndex; //获取选项中的索引,selectIndex表示的是当前所选中的index
value1_obj[0].options[index].value;//获取选项中options的value值
value1_obj[0].options[index].text;//获取选项中options的value值
通过标签名称获得下拉框的值:
var value = document.myForm.mySelect.value;
//myForm是表单form的name
//mySelect是下拉框selece的name
推荐阅读
