我试图在强标签之间存储最高值,然后按类&#34过滤结果;条件确定"在jquery。有人可以帮我解决这个问题吗?
<div id="my_list">
<div class="my_class">
<div>
<p> <strong>12</strong>
</p>
<p class="condition ok"></p>
</div>
<div class="my_class">
<div>
<p> <strong>10</strong>
</p>
<p class="condition ok"></p>
</div>
<div class="my_class">
<div>
<p> <strong>25</strong>
</p>
<p class="condition"></p>
</div>
<div class="my_class">
<div>
<p> <strong">20</strong>
</p>
<p class="condition ok"></p>
</div>
答案 0 :(得分:1)
您似乎在 HTML 时遇到了一些错误。
<div class='my_class'>
之后,看看小提琴得到结果:https://jsfiddle.net/2hf2qt2j/
var max = -1;
$("strong").each(function(){
if($(this).parent().next("p").is('.condition.ok'))
max = Math.max(max, $(this).text());
});
alert(max);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="my_list">
<div class="my_class">
<div>
<p> <strong>125</strong></p>
<p class="condition ok"></p>
</div>
</div>
<div class="my_class">
<div>
<p> <strong>10</strong></p>
<p class="condition ok"></p>
</div>
</div>
<div class="my_class">
<div>
<p> <strong>525</strong></p>
<p class="condition"></p>
</div>
</div>
<div class="my_class">
<div>
<p> <strong>20</strong></p>
<p class="condition ok"></p>
</div>
</div>
<强>更新强>
如果强有负值,请查看https://jsfiddle.net/y09vq8p5/