我正在尝试计算 yes 的数量,直到由 :contains(certain sring) 指定的特定跨度。我基本上只是想搜索这组问题的前半部分,看看有多少是的。这是我尝试过的代码:
<div class="ce-modal-container">
<div class="ce-cf-container">
<span class="ce-cf-html-label">Have you chosen your exit path and/or successor?:</span>
<span class="ce-cf-html-field"> Yes</span>
</div>
<div class="ce-cf-container">
<span class="ce-cf-html-label">Have you chosen your exit path and/or successor?:</span>
<span class="ce-cf-html-field"> No</span>
</div>
<div class="ce-cf-container">
<span class="ce-cf-html-label">Have you done well this quarter?:</span>
<span class="ce-cf-html-field"> No</span>
</div>
<div class="ce-cf-container">
<span class="ce-cf-html-label">Have you chosen your exit path and/or successor?:</span>
<span class="ce-cf-html-field"> Yes</span>
</div>
<div class="ce-cf-container">
<span class="ce-cf-html-label">Have you chosen your exit path and/or successor?:</span>
<span class="ce-cf-html-field"> Yes</span>
</div>
</div>
<script>
var spanYes = $("span.ce-cf-html-field:contains('Yes')"),
secondHalf = $("span.ce-cf-html-label:contains('done well')"),
searchtxtall = spanYes.length;
searchFirstHalf = $(".ce-cf-container").nextUntil(secondHalf).spanYes.length;
console.log(searchtxtall); //should return 3
console.log(searchFirstHalf); //should return 1
</script>
在此先感谢我知道这是很多代码。