用jquery和js获取select标签中选中的option值及文本


用jquery和js获取select标签中选中的option值及文本


jquery:

复制代码
//获取选中的option的文本值
$("#id option:selected").text();  
$("#id").find("option:selected").text()

//获取select中option的被选中的value值
$("#id").val(); 
$("#id option:selected").val();
$("#id").find("option:selected").val()
复制代码

js:

var sel=document.getElementById("id"); 
var index = sel.selectedIndex; // 选中索引
sel.options[index].value;//要的值
sel.options[index].text;//要的文本


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM