Get the selected option id with jQuery

前端 未结 4 940
孤独总比滥情好
孤独总比滥情好 2020-12-02 10:31

I\'m trying to use jQuery to make an ajax request based on a selected option.

Is there a simple way to retrieve the selected option id (e.g. \"id2\"

4条回答
  •  伪装坚强ぢ
    2020-12-02 11:05

    You can get it using the :selected selector, like this:

    $("#my_select").change(function() {
      var id = $(this).children(":selected").attr("id");
    });
    

提交回复
热议问题