我使用的是jquery的星级插件"Raty“https://github.com/wbotelhos/raty。我正在用PHP从数据库中生成一个结果集。这也包括得分。我希望为每个单独的评分组件设置分数属性。我该怎么做呢?我使用这个语法来显示星星。
$('.stars_small').raty({
readOnly : true,
half : true,
score : 2,
space : false
});
<div class="stars_small"></div>在一个页面中有许多带有动态生成类"stars_small“的div。我想为每个div设置"score“。
发布于 2012-12-07 15:27:03
$('.stars_small').raty({
readOnly : true,
half : true,
score: function() {
return $(this).attr('data-rating');
}
space : false
}); 这对我来说很好。该插件在每个带有class="stars_small"的div中添加一个隐藏的文本框,如下所示
<div class="stars_small">
<input type="hidden" name="score" value="3.5" readonly="readonly">
</div>所以我只用来自数据库查询的数字设置了value属性。
发布于 2012-09-28 12:35:16
尝尝这个
$('.stars_small').each(function() {
$(this).raty({
readOnly : true,
half : true,
score : 2,
space : false
});
});发布于 2012-09-28 12:44:26
假设您已经用PHP生成了JS代码行:
// lines of JS generated with a loop in PHP (for the rate content)
var rates = [];
rates.push({...one rate coming from PHP...});
rates.push({...one rate coming from PHP...});
// etc...你可以用以下命令运行你的星级评定:
$(document).ready(function() {
$(".starts_small").each(function(index, element) {
$(this).raty(rates[index]);
});
});https://stackoverflow.com/questions/12633576
复制相似问题