jQuery Get Selected Option From Dropdown

前端 未结 30 3315
梦如初夏
梦如初夏 2020-11-22 02:56

Usually I use $(\"#id\").val() to return the value of the selected option, but this time it doesn\'t work. The selected tag has the id aioConceptName

30条回答
  •  一向
    一向 (楼主)
    2020-11-22 03:24

    Probably your best bet with this kind of scenario is to use jQuery's change method to find the currently selected value, like so:

    $('#aioConceptName').change(function(){
    
       //get the selected val using jQuery's 'this' method and assign to a var
       var selectedVal = $(this).val();
    
       //perform the rest of your operations using aforementioned var
    
    });
    

    I prefer this method because you can then perform functions for each selected option in a given select field.

    Hope that helps!

提交回复
热议问题