dlc*_*ers 4 jquery filter find
假设我编写了一个DOM片段:
var dom = $("
<div id='root' class='abc'>
<div id='child1' class='xxx'>no-match</div>
<div id='child2' class='abc'>match!</div>
<div id='child3' class='xxx'>no-match</div>
</div>
");
Run Code Online (Sandbox Code Playgroud)
我想用'.abc'检索所有元素(即#root和#child2)
dom.find('.abc')将返回所有匹配的子元素(即只是#
child2 )dom.filter('.abc')将返回所有匹配的根元素(即只是#root)
我怎么能:
- 拨打一个同时找到#root和#child2的电话,或者
- 结合find()和filter()的结果
我已经看到其他关于"组合"结果的帖子,例如: 如何组合两个jQuery结果, 但这不是真正的"组合",而是"将更多结果附加到预先存在的结果"
我真正想要做的是类似于$.extend():
var one = dom.find('.abc');
var two = dom.filter('.abc');
var three = combine(one, two);
// or one.somefcn(two); // One is augmented
// or three = one.somefcn(two); //
Run Code Online (Sandbox Code Playgroud)
任何信息/想法将不胜感激
您可以使用add()组合选择器:
var $all = dom.find('.abc').add(dom.filter('.abc'));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1898 次 |
| 最近记录: |