2009-10-06 59 views

回答

2
var selects = $('select').filter(function() { 
    return $(this).find('option').length === 2 
}); 

或:

var selects = $('select').filter(function() { 
    return $('option', this).length === 2; 
}); 
3

這也將工作:

$('select:has(option:first-child + option:last-child)'); 

基本上它會查找包含option元素是第一個孩子,是鄰近的一個select元素option那是最後一個孩子。

+0

不錯,我沒有想到這一點。 – 2009-10-06 19:02:09