javascript獲取select標簽選中的值
來源:易賢網(wǎng) 閱讀:1372 次 日期:2016-06-16 15:44:36
溫馨提示:易賢網(wǎng)小編為您整理了“javascript獲取select標簽選中的值”,方便廣大網(wǎng)友查閱!

這篇文章主要介紹javascript獲取select標簽選中的值方法,比較實用,需要的朋友可以參考下。

代碼如下:

var obj = document.getElementById("testSelect"); //定位id

var index = obj.selectedIndex; // 選中索引

var text = obj.options[index].text; // 選中文本

var value = obj.options[index].value; // 選中值

jQuery中獲得選中select值

第一種方式

代碼如下:

$('#testSelect option:selected').text();//選中的文本

$('#testSelect option:selected').val();//選中的值

$("#testSelect").get(0).selectedIndex;//索引

第二種方式

代碼如下:

$("#tesetSelect").find("option:selected").text();//選中的文本

$("#tesetSelect").find("option:selected").val();

$("#tesetSelect").find("option:selected").get(0).selectedIndex;

以上就是javascript獲取select標簽選中的值的全部內容,希望能給大家一個參考

更多信息請查看網(wǎng)絡編程
易賢網(wǎng)手機網(wǎng)站地址:javascript獲取select標簽選中的值
關于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機站點

版權所有:易賢網(wǎng)