0

我在只读模式下使用 Raty 星插件,评级数字来自数据库,我有 7 个分数,我想要每个人的星级评级。即使我将 div 放在一个 while 循环中,我也只能得到一个星级。有人可以帮帮我吗?

$(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 } ?>
4

1 回答 1

2

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

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代码

 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 } ?>
于 2014-03-25T06:10:17.557 回答