Get selected value of a dropdown's item using jQuery

后端 未结 30 1535
广开言路
广开言路 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 06:59

    For Normal Page loaded dropdowns

      $("#dropDownId").on('change',function(){
         var value=$(this).val();
         alert(value);
      });
    

    for dynamically added options Make sure to keep the id unique

      $(document).on('change','#dropDownId',function(){
        var value=$(this).val();
        alert(value)
      });
    

提交回复
热议问题