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

后端 未结 9 1272
青春惊慌失措
青春惊慌失措 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 02:05

    You can use find to look for the selected option that is a descendant of the node(s) pointed to by the current jQuery object:

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

    Since this is likely an immediate child, I would actually suggest using .children instead:

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

提交回复
热议问题