hymn

忽有故人心头过,回首山河已是秋。

  menu
132 文章
0 浏览
3 当前访客
ღゝ◡╹)ノ❤️

实现 select中指定option选中触发事件

一:javascript原生的方法

1:拿到select对象: var myselect=document.getElementById("test");

2:拿到选中项的索引:var index=myselect.selectedIndex ; // selectedIndex代表的是你所选中项的index

3:拿到选中项options的value: myselect.options[index].value;

4:拿到选中项options的text: myselect.options[index].text;

二:jquery方法

1:var options=$("#test option:selected"); //获取选中的项

2:alert(options.val()); //拿到选中项的值

3:alert(options.text()); //拿到选中项的文本


标题:实现 select中指定option选中触发事件
作者:hymn
地址:https://www.dxyhymn.com/articles/2020/07/02/1593662720277.html