Get selected value of a dropdown's item using jQuery

后端 未结 30 1978
广开言路
广开言路 2020-11-22 06:48

How can I get the selected value of a dropdown box using jQuery?
I tried using

var value = $(\'#dropDownId\').val();

and



        
30条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-22 07:18

    Try this jQuery,

    $("#ddlid option:selected").text();
    

    or this javascript,

     var selID=document.getElementById("ddlid");
     var text=selID.options[selID.selectedIndex].text;
    

    If you need to access the value and not the text then try using val() method instead of text().

    Check out the below fiddle links.

    Demo1 | Demo2

提交回复
热议问题