javascript獲取select標(biāo)簽選中的值

字號(hào):


    這篇文章主要介紹javascript獲取select標(biāo)簽選中的值方法,比較實(shí)用,需要的朋友可以參考下。
    代碼如下:
    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標(biāo)簽選中的值的全部內(nèi)容,希望能給大家一個(gè)參考