jQuery Get Selected Option From Dropdown

前端 未结 30 4105
梦如初夏
梦如初夏 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

    If you are in event context, in jQuery, you can retrieve the selected option element using :
    $(this).find('option:selected') like this :

    $('dropdown_selector').change(function() {
        //Use $option (with the "$") to see that the variable is a jQuery object
        var $option = $(this).find('option:selected');
        //Added with the EDIT
        var value = $option.val();//to get content of "value" attrib
        var text = $option.text();//to get  content
    });
    

    Edit

    As mentioned by PossessWithin, My answer just answer to the question : How to select selected "Option".

    Next, to get the option value, use option.val().

提交回复
热议问题