gpt4 book ai didi

jquery - 使两个 jQuery 选择相交

转载 作者:行者123 更新时间:2023-12-01 07:12:21 25 4
gpt4 key购买 nike

jQuery 有 ability to union the results of two selections ,使用.add() :

var foosAndBars = $(".foo").add(".bar");//选择所有元素类.foo或.bar

但我需要执行两组的交集:

var allTRs = $("#lvTransactions").find("[data-language]").closest("tr")
var trMatchingLanguage= allTRs.find("[data-language]").filter("[data-language='pascal'],[data-language='C#'],[data-langauge='Ook']").closest("tr");
var trMatchingTag = allTRs.find("data-tag").filter("[data-tag='wpf'").closest("tr");

我需要两个集合中通用的 TR 元素,因为这些是要显示的元素:

allTRs.hide();    
trMatchingLanguage.intersect(trMatchingTag ).show();

编辑:jsFiddle :

显示具有以下内容的所有行:

  • 数据语言:pascalC#
  • 数据标签:wpf

具有以下示例表:

<div id="lvTransactions">
<table>
<thead>
<tr><th>Question</th><th>Lanaguage</th><th>Tag</th></tr>
</thead>
<tr>
<td>How to</td>
<td data-language="C">C</td>
<td data-tag="wpf">Windows Presentation Foundation</td>
</tr>
<tr>
<td>Why does</td>
<td data-language="pascal">Pascal</td>
<td data-tag="dwm">Windows Presentation Foundation</td>
</tr>
<tr>
<td>Why can't</td>
<td data-language="pascal">Pascal</td>
<td data-tag="wpf">Desktop Window Manager</td>
</tr>
<tr>
<td>Does it</td>
<td data-language="C#">C#</td>
<td data-tag="wpf">Desktop Window Manager</td>
</tr>
<tr>
<td>Where is</td>
<td data-language="Java">Java</td>
<td data-tag="wpf">Windows Presentation Foundation</td>
</tr>
</table>
</div>

现在我有(错误的)代码(显示并集,而不是交集):

//Only show rows that are both C#/Pascal and WPF

var allTRs = $("#lvTransactions").find("[data-language]").closest("tr")

var theLanguageTRs = allTRs.find("[data-language]").filter("[data-language='pascal'],[data-language='C#'],[data-langauge='ook']").closest("tr");
var theTagTRs = allTRs.find("[data-tag]").filter("[data-tag='wpf']").closest("tr");

最佳答案

像这样简单的事情怎么样:

$(array1).filter(array2);

引用:$.filter()

关于jquery - 使两个 jQuery 选择相交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24760857/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com