jQuery Get Selected Option From Dropdown

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

    Straight forward and pretty easy:

    Your dropdown

    
    

    Jquery code to get the selected value

    $('#aioConceptName').change(function() {
        var $option = $(this).find('option:selected');
    
        //Added with the EDIT
        var value = $option.val(); //returns the value of the selected option.
        var text = $option.text(); //returns the text of the selected option.
    });
    

提交回复
热议问题