1 回答
TA贡献1799条经验 获得超9个赞
你alert ( $("#blah1_1 .inner").val() );
应该alert ( $("#blah1_1 .inner").text() );
那么您可以使用属性选择器来选择这两个集合blah1_*
并blah2_*
然后使用.each() jQuery 方法迭代标签:
然后进行比较:
$(document).ready(function() {
const elms1 = $('[id^="blah1"]');
const elms2 = $('[id^="blah2"]');
const labels1 = elms1.find('label');
const labels2 = elms2.find('label');
labels1.each(function(index1, el1){
labels2.each(function(index2, el2){
console.log($(el2).text() === $(el1).text())
})
})
})
<div id="blah1_1">
<label for="blah1_1">
<span class="inner">hi</span>
</label>
</div>
<div id="blah1_2">
<label for="blah1_2">
<span class="inner">yes</span>
</label>
</div>
<div id="blah2_1">
<label for="blah2_1">
<span class="inner">yes</span>
</label>
</div>
<div id="blah2_2">
<label for="blah2_2">
<span class="inner">no</span>
</label>
</div>
<script
src="https://code.jquery.com/jquery-3.4.1.min.js"
integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
crossorigin="anonymous"></script>
- 1 回答
- 0 关注
- 83 浏览
添加回答
举报