javascript;gutter:true;
误区:</p>
<pre><code> 一直以为jquery获取select中option被选中的文本值,是这样写的:
$("#s").text(); //获取所有option的文本值
</code></pre>
<p>实际上应该这样:</p>
<pre><code> $("#s option:selected").text(); //获取选中的option的文本值
</code></pre>
<p>获取select中option的被选中的value值,</p>
<pre><code> $("#s").val();
$("#s option:selected").val();
</code></pre>
<p>js获取select选中的值:</p>
<pre><code> var sel=document.getElementById("select1");
var index = sel.selectedIndex; // 选中索引
albumid= sel.options[index].value;//要的值
</code></pre>
<p>
Original: https://www.cnblogs.com/qingmuchuanqi48/p/14885255.html
Author: King-DA
Title: Jquery获取selelct选中值
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/553084/
转载文章受原作者版权保护。转载请注明原作者出处!