select选项改变时获取选中的option的值
本来天真的以为直接this.value()就能去到select的值,可事实并非那么回事。
<script>
document.getElementById('select').onchange=function(){
console.log(this.value) // return '';
}
</script>
this是select下拉框对象,是一个集合,so,打印出this.options来看看

good,找到了,selectedIndex,就是这货,选中的值的索引
ok,现在我们可以取值了
document.getElementById('select').onchange=function(){
console.log(this.options[this.options.selectedIndex].value)
}
select选项改变时获取选中的option的值的更多相关文章
- JS动态获取select中被选中的option的值,并在控制台输出
生活城市: <select id="province"> <option>河南省</option> <option>黑龙江省< ...
- jq获取被选中的option的值。jq获取被选中的单选按钮radio的值。
温故而知新,一起复习下jq的知识点. (1) jq获取被选中的option的值 <select id="select_id"> <option value=&qu ...
- select的onchange事件获取不了option的value
一,select的onchange事件获取不了option的value是当你使用JQ($("#xxx").val())方法的获取的值一直提示undefined 二,解决方法: va ...
- jquery获取选中的文本和值
jquery获取选中的文本和值 1.说明 (1)获取select下拉框选中的索引 $("#selection").get(0).selectedIndex; (2)获取 ...
- select获取选中的option(包含value和text,重点是text怎么获取)
简单描述:后台需要获取到select标签选择的内容,也就是text,该怎么取呢?很简单. 代码: //hml代码<div class="col-md-6"> <l ...
- JS获取select被选中的option的值
一:JavaScript原生的方法 1:拿到select对象: var myselect=document.getElementById(“test”); 2:拿到选中项的索引:var index=m ...
- [thml]HTML select标签 获取选中的option的value及Text内容
很简单的select标签: <select id="hello" onchange="getContent(this.value,this.options[this ...
- 获取select被选中的option的值
<select id="select"> <option>绥江</option> <option>西江</ ...
- 怎样用jQuery拿到select中被选中的option的值
1.首先要保证select中每一个option标签都有value属性: 2.jquery的写法 1 $('#sele').val()//这里假设select的id是sele,这样可以获取当前选中的op ...
随机推荐
- lightoj 1236 正整数唯一分解定理
A - (例题)整数分解 Crawling in process... Crawling failed Time Limit:2000MS Memory Limit:32768KB 6 ...
- Truncate Table user
Truncate Table 百科名片 Truncate是一个能够快速清空资料表内所有资料的SQL语法.并且能针对具有自动递增值的字段,做计数重置归零重新计算的作用. 目录 语法 参数 注释 示例 ...
- NFine常见错误
1.新增数据录入录入不进去提示:An error occurred while updating the entries.See the inner exception for details. 这样 ...
- cf C. Tourist Problem
http://codeforces.com/contest/340/problem/C #include <cstdio> #include <cstring> #includ ...
- 【转】如何在ubuntu12.04设置adb驱动
原文网址:http://www.xuebuyuan.com/1475698.html 在ubuntu上adb驱动不用像在windows上一样需要额外装,只需要写一个配置文件就可以,下面是设置的步骤: ...
- Largest Rectangle in Histogram 解答
Question Given n non-negative integers representing the histogram's bar height where the width of ea ...
- hdu2059 龟兔赛跑
hdu2059 龟兔赛跑 动态规划 题目描述: Problem Description 据说在很久很久以前,可怜的兔子经历了人生中最大的打击——赛跑输给乌龟后,心中郁闷,发誓要报仇雪恨,于是躲进了杭州 ...
- dig命令(转载)
dig命令使用大全(linux上域名查询) 可以这样说,翻译本篇文档的过程就是我重新学习DNS的过程,dig命令可以帮助我们学习DNS的原理,配置,以及其查询过程.以前使用dig仅仅是查询一下A记录或 ...
- 提高xshell使用效率
1.快速命令集. 2.鼠标复制粘贴设置. 3.配色方案. 4.esc切换到英文输入. 设置入口:
- STS(Spring Tool Suite)使用前准备
sts 的基础框架拿的eclipse的,你可以理解为eclipse + spring插件的高级升华版.在使用上可以很大限度的参考eclipse的操作. 首先,调整字体. 中文很麻烦的,因为编码问题.习 ...