次のようなさまざまな行を持つテーブルを作成しました。評価の開始にはrateyを使用します。
while ($row = pg_fetch_assoc($rs)) {
echo "<tr>";
echo "<td>" . $row['question_id'] . "</td>";
...
echo "<td><div> \r \n <div id=\"score-question" . $row['question_id'] ."\" data-score=\"" . $row['rating'] . "\"></div> \r \n </div> \r \n</td>";
...
echo "</tr>";
}
<script type="text/javascript">
$(function() {
$.fn.raty.defaults.path = '../plugins/raty/lib/img';
$('#score-question1').raty({
readOnly: true,
noRatedMsg: "Press edit to change the rating",
score: function() {
return $(this).attr('data-score');
}
});
$('#score-question2').raty({
readOnly: true,
noRatedMsg: "Press edit to change the rating",
score: function() {
return $(this).attr('data-score');
}
});
$('#set-action').on('click', function() {
var options = $('#set-function-demo').val(),
command = "$('#function-demo').raty('set', " + options + ");";
eval(command);
});
$('#destroy-action').on('click', function() {
$('#function-demo').raty('destroy');
});
});
</script>
星評価バーを制御するために JavaScript 関数を使用します。同じ名前の 2 つの div を持つことはできないため、別の名前を使用する必要がありますが、各評価バーに対して個別の関数を使用する必要があります。この問題を解決するためのより良い方法はありますか? 私はJavaScriptの経験がないので、おそらく初心者の質問です