用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;//要的文本


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM