用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 @ 2020-07-21 10:08  海角之上  阅读(1402)  评论(1编辑  收藏  举报