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

后端 未结 9 1210
青春惊慌失措
青春惊慌失措 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/

    0 讨论(0)
  • 2020-12-13 02:00

    This should work:

    $(this).find('option:selected').text();
    
    0 讨论(0)
  • 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();
    
    0 讨论(0)
提交回复
热议问题