用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;//要的文本
posted @ 2021-12-09 09:54  前端白雪  阅读(860)  评论(0)    收藏  举报