我希望能夠匹配給定上下文中的所有元素,包括上下文元素本身。
這是我目前使用的代碼,但它似乎效率低下。有沒有更好的辦法?
注意:我使用jQ 1.3.2,但我很快就會升級,所以我對1.4解決方案也很感興趣。
var context = $('#id');
var filters = '.class1, .class2';
// take context itself if it matches filters
$(context).filter(filters)
// add anything matching filters inside context
.add($(filters, context))
注:.add($(f,c))
作品JQ 1.3作爲.add(f,c)
在JQ 1.4