jQuery Get Selected Option From Dropdown

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

    Use the jQuery.val() function for select elements, too:

    The .val() method is primarily used to get the values of form elements such as input, select and textarea. In the case of select elements, it returns null when no option is selected and an array containing the value of each selected option when there is at least one and it is possible to select more because the multiple attribute is present.

    $(function() {
      $("#aioConceptName").on("change", function() {
        $("#debug").text($("#aioConceptName").val());
      }).trigger("change");
    });
    
    
    
    

提交回复
热议问题