Jquery Raty开始插件:为多个div设置得分

Jay*_*dev 2 php jquery raty

我正在使用jquery星级评级插件"Raty" https://github.com/wbotelhos/raty.我正在使用PHP从数据库生成结果集.这也包括得分.我想为每个评级组件设置分数属性.我怎样才能做到这一点?我正在使用这种语法来显示星星.

$('.stars_small').raty({
      readOnly : true,
      half  : true,
      score : 2,
      space : false
 });  

<div class="stars_small"></div>
Run Code Online (Sandbox Code Playgroud)

在单个页面中有许多div,动态生成类"stars_small".我想为每个div设置"得分".

Jay*_*dev 5

$('.stars_small').raty({
             readOnly : true,
             half  : true,
             score: function() {
                      return $(this).attr('data-rating');
                     }
              space : false
         });  
Run Code Online (Sandbox Code Playgroud)

这对我来说很好.该插件在每添加一个文本框隐藏divclass="stars_small" 这样的

<div class="stars_small">
     <input type="hidden" name="score" value="3.5" readonly="readonly">
</div>
Run Code Online (Sandbox Code Playgroud)

所以我只value使用来自数据库查询的数字设置属性.