我知道以下事情
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)
任何线索?
你需要使用逗号而不是+来获得后代.另请注意.val()您不需要使用.attr
var combo=$('#select');
var selectedVal = $(combo, 'option:selected').val();
// ^^
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2324 次 |
| 最近记录: |