这是轮盘赌游戏,您可以获得"coin coin-ct"
或"coin coin-t"
或"coin coin-bonus"
。如果可能,我如何知道行重复"coin coin-ct"
变量的3或4次完整时间?我是新手,对不起误会。
作为:
<div class="icon-box">
<div class="coin coin-ct"></div>
<div class="round">#2721574 - 13</div>
</div>
<div class="icon-box">
<div class="coin coin-ct"></div>
<div class="round">#2721573 - 11</div>
</div>
<div class="icon-box">
<div class="coin coin-ct"></div>
<div class="round">#2721572 - 10</div>
</div>
完整代码示例(现实生活中的更多内容):
<div class="icon-box">
<div class="coin coin-ct"></div>
<div class="round">#2721574 - 13</div>
</div>
<div class="icon-box">
<div class="coin coin-ct"></div>
<div class="round">#2721573 - 11</div>
</div>
<div class="icon-box">
<div class="coin coin-bonus"></div>
<div class="round">#2721572 - 0</div>
</div>
<div class="icon-box">
<div class="coin coin-t"></div>
<div class="round">#2721571 - 6</div>
</div>
<div class="icon-box">
<div class="coin coin-ct"></div>
<div class="round">#2721570 - 9</div>
</div>
答案 0 :(得分:1)
对每一行使用JQuery选择器,选择其类为coin coin-ct
的子项。
<强> $( “行”)强>
一个类选择器,它获取类row
的所有元素。 (class="row"
)
<强> $( “行”)。每个(函数(ITM){})强>
所有元素的迭代器都有类row
。
<强> $(本)。儿童( “div.icon盒”)强>
用于选择div
所选元素的所有子元素并具有类icon-box
如下所示:
$(".row").each(function(itm) {
$(this)
.children("div.icon-box")
.each(function(obj) {
console.log($(this).children(".coin.coin-ct").length)
});
console.log("-----------------------------");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="row">
<div class="icon-box">
<div class="coin coin-ct"></div>
<div class="round">#2721574 - 13</div>
</div>
<div class="icon-box">
<div class="coin coin-ct"></div>
<div class="round">#2721573 - 11</div>
</div>
<div class="icon-box">
<div class="coin coin-bonus"></div>
<div class="round">#2721572 - 0</div>
</div>
<div class="icon-box">
<div class="coin coin-t"></div>
<div class="round">#2721571 - 6</div>
</div>
<div class="icon-box">
<div class="coin coin-ct"></div>
<div class="round">#2721570 - 9</div>
</div>
</div>
<div class="row">
<div class="icon-box">
<div class="coin coin-ct"></div>
<div class="round">#2721574 - 13</div>
</div>
<div class="icon-box">
<div class="coin coin-ct"></div>
<div class="round">#2721573 - 11</div>
</div>
<div class="icon-box">
<div class="coin coin-bonus"></div>
<div class="round">#2721572 - 0</div>
</div>
<div class="icon-box">
<div class="coin coin-t"></div>
<div class="round">#2721571 - 6</div>
</div>
<div class="icon-box">
<div class="coin coin-ct"></div>
<div class="round">#2721570 - 9</div>
</div>
</div>
<div class="row">
<div class="icon-box">
<div class="coin coin-ct"></div>
<div class="round">#2721574 - 13</div>
</div>
<div class="icon-box">
<div class="coin coin-ct"></div>
<div class="round">#2721573 - 11</div>
</div>
<div class="icon-box">
<div class="coin coin-bonus"></div>
<div class="round">#2721572 - 0</div>
</div>
<div class="icon-box">
<div class="coin coin-t"></div>
<div class="round">#2721571 - 6</div>
</div>
<div class="icon-box">
<div class="coin coin-ct"></div>
<div class="round">#2721570 - 9</div>
</div>
</div>
阅读JQuery selectors, each function, children
希望这会对你有所帮助。