首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Raty多重评级

Raty多重评级
EN

Stack Overflow用户
提问于 2014-03-25 06:05:26
回答 1查看 933关注 0票数 0

我使用的是只读模式下的Raty星插件,评级号码来自数据库,我有7分,我希望它们中的每一个都有星级。即使我把div放了一段时间循环,我只得到了一颗星级。有人能帮我吗?

代码语言:javascript
复制
$(function() {
    $('#rate').raty({
    path     : '../img',
    readOnly   : true,
     size     : 24,
    starHalf : 'star-half-big.png',
    starOff  : 'star-off-big.png',
    starOn   : 'star-on-big.png',
     score: function() {
    return $(this).attr('data-score');
    }
  });
  });

while($row = $result->fetch_assoc()){ ?>
<div id="rate" data-score="<?php echo $row['rating'];"></div><!--even though I have 7 ratings in the table only one is showing up here -->
 <?php } ?>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-03-25 06:10:17

尝试使用class而不是Id,因为Id应该是唯一的

JAVASCRIPT代码

代码语言:javascript
复制
    $(function() {
        $('.rate').raty({
            path     : '../img',
            readOnly   : true,
             size     : 24,
            starHalf : 'star-half-big.png',
            starOff  : 'star-off-big.png',
            starOn   : 'star-on-big.png',
             score: function() {
            return $(this).attr('data-score');
            }
        });
  });

PHP代码

代码语言:javascript
复制
 while($row = $result->fetch_assoc()){ ?>
    <div class="rate" data-score="<?php echo $row['rating'];"></div><!--even though I have 7 ratings in the table only one is showing up here -->
 <?php } ?>
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22626625

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档