从JQuery中的select变量中获取选定的值

s.k*_*aul -2 jquery

我知道以下事情

 var selectedVal = $('#select option:selected').attr('value');
Run Code Online (Sandbox Code Playgroud)

但是,我想做点什么

  var combo=$('#select');     
  var selectedVal = $(combo + 'option:selected').attr('value');
Run Code Online (Sandbox Code Playgroud)

任何线索?

Ant*_*ton 6

你需要使用逗号而不是+来获得后代.另请注意.val()您不需要使用.attr

  var combo=$('#select');     
  var selectedVal = $(combo, 'option:selected').val();
  //                       ^^
Run Code Online (Sandbox Code Playgroud)

DEMO