获得select被选中option的value和text

时间:2021-09-06 22:56:42   收藏:0   阅读:22
js方法:
var myselect=document.getElementById(“test”);  //拿到select对象
var index=myselect.selectedIndex ; // selectedIndex代表的是你所选中项的index,拿到选中项的索引
myselect.options[index].value;  //拿到选中项options的value
myselect.options[index].text;  //拿到选中项options的text 
jQuery方法:
var options=$(“#test option:selected”); //获取选中的项
$(“#test option:selected”).val(); //拿到选中项的值
$(“#test option:selected”).text(); //拿到选中项的文本

  

原文:https://www.cnblogs.com/xi-li/p/15232551.html

评论(0)
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!