How to get $(this) selected option in jQuery?

后端 未结 9 1251
青春惊慌失措
青春惊慌失措 2020-12-13 01:18

The following code works:

$(\"#select-id\").change(function(){
  var cur_value = $(\'#select-id option:selected\').text();
  . . .
});

How

9条回答
  •  独厮守ぢ
    2020-12-13 01:58

    var cur_value = $(this).find('option:selected').text();
    

    Since option is likely to be immediate child of select you can also use:

    var cur_value = $(this).children('option:selected').text();
    

    http://api.jquery.com/find/

提交回复
热议问题