gpt4 book ai didi

javascript - 你可以在 jQuery 中使用 length() 按图像名称计算元素吗?

转载 作者:太空宇宙 更新时间:2023-11-03 23:39:55 24 4
gpt4 key购买 nike

我正在尝试整理一个评论“摘要”部分,其中包含 5 星、4 星、3 星评论等的总数。我需要做的是计算每个“评论级别”的实例产品页面并输出编号。例如如果一个产品有 50 条评论,其中 14 条是 5 星,我需要将该数字作为“14”输出到页面。

评论之间的唯一区别不是 id 或类,而是它输出的图像名称(即星数)。请参阅下面的图像文件名了解我的意思:

<ol class="ProductReviewList">
<li class="">
<h4 class="ReviewTitle">
Cool hammock!
<img src="http://cdn2.bigcommerce.com/rc71b9995f4a706510d16ad47d2472c26eb88e9bf/themes/HealthBeauty/images/IcoRating4.png" alt="">
</h4>
<p class="Meta">
Posted by Matina Keller on 6th Jan 2014
</p>
<p>I love this hammock! I got the single brazilian for my courtyard out the side and it fits snug between two patio posts. I can easily put it up and take it down whenever i want. It's really comfortable and easy to fall asleep in. The material is of very high quality and far better than my old hammock. Delivery was about 4 days to adelaide FYI.</p>
<hr>
</li> <li class="Alt">
<h4 class="ReviewTitle">
So comfortable!
<img src="http://cdn2.bigcommerce.com/rc71b9995f4a706510d16ad47d2472c26eb88e9bf/themes/HealthBeauty/images/IcoRating5.png" alt="">
</h4>
<p class="Meta">
Posted by Kendra Lovell on 17th Dec 2013
</p>
<p>I bought one of these for my daughter and she loves it. It's really comfortable and the colours are so pretty. Thanks siesta hammocks.</p>
<hr>
</li> <li class="">
<h4 class="ReviewTitle">
Great customer service and product!
<img src="http://cdn2.bigcommerce.com/rc71b9995f4a706510d16ad47d2472c26eb88e9bf/themes/HealthBeauty/images/IcoRating5.png" alt="">
</h4>
<p class="Meta">
Posted by Susan Knight on 20th Nov 2013
</p>
<p>I must have had a million questions about this but the staff on the online chat answered all of them! Really good customer service and ordering system. The hammock itself is really good quality. So relaxing in the afternoon sun. Got the double hook kits and put it up between some wooden posts we already had under our pergola. Got the frame too in case we want to put it somewhere else. Really easy to assemble and is very sturdy. All up it's been a great experience shopping with siesta so thanks.</p>
<hr>
</li>
</ol>

在最后查看图像是 IcoRating4.png 还是 IcoRating5.png

我想知道我是否可以使用 .length() 来计算文档中的元素,而不是通过 id 或类,而是通过文件名中的字符串,或者通过图像名称或类似的变体。这可能吗?

I've put together a fiddle here if that helps

谢谢!

最佳答案

当然可以:

var count = $('img[src$="IcoRating4.png"]').length;

引用:http://api.jquery.com/attribute-ends-with-selector/

关于javascript - 你可以在 jQuery 中使用 length() 按图像名称计算元素吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23144275/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com