我已经使用过往帖子的帮助到目前为止,但我无法让这个工作。我想测试group1数组中是否存在所有group2数组元素。目前,我的结果与我想要的相反。我已经尝试在“比较数组”中反转代码。 jQuery部分,但没有运气。示例结果在下面的列中给出。 https://jsfiddle.net/v82pfx2w/。有人能说清楚这个吗?
group1: group1: group1:
Luxembourg Greece Greece
Netherlands Netherlands Netherlands
Belgium Luxembourg Luxembourg
Belgium Belgium
group2
Netherlands group2 group2
Greece Netherlands Luxembourg
Luxembourg Luxembourg Belgium
Belgium Belgium
NO MATCH YES MATCH YES MATCH
https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js
<div id="containerStore">
<div class='AggregCountriesBNLUX'>
<label>Netherlands</label>
<label>Greece</label>
<label>Luxembourg</label>
<label>Belgium</label>
</div>
<div class='AggregCountriesWEur'>
<label>Netherlands</label>
<label>Luxembourg</label>
<label>Belgium</label>
</div>
<div class='AggregCountriesWEur'>
<label>Luxembourg</label>
<label>Belgium</label>
</div>
</div>
var group1 = [];
group1 = ['Luxembourg', 'Netherlands', 'Belgium']
$('#containerStore div[class^="AggregCountries"]').each(function(i, obj) {
group2 = $(this).map(function() {
return $.trim($(this).text());
})
.get();
group2 = group2.join();
// compare arrays:
var compareGroups = group1.every(function(val) {
return group2.indexOf(val) >= 0;
})
alert(compareGroups);
});