评级明星PHP / JS

时间:2018-05-01 13:48:12

标签: javascript php twig rating-system

我需要在我的项目中实施评级星,但我的js不起作用。谁能帮我?

Javascript代码:

let $star_rating = $('.list-group-item .fa');
let SetRatingStar = function() {
  return $star_rating.each(function() {
    if (parseInt($star_rating.siblings('input.rating-value').val()) >= parseInt($(this).data('rating'))) {
      return $(this).removeClass('fa-star-o').addClass('fa-star');
    } else {
      return $(this).removeClass('fa-star').addClass('fa-star-o');
    }
  });
};
$star_rating.on('click', function() {
  $star_rating.siblings('input.rating-value').val($(this).data('rating'));
  return SetRatingStar();
});
SetRatingStar();
$(document).ready(function() {
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

以下是我的观点:

<div class="d-inline-flex">
    <input type="checkbox" id="checkAll" onclick="toggle(this);">
    <p class="mt-3 mb-0 ml-1">Tous vus</p>
</div>
{% for episode in episodes %}
    <li class="list-group-item bgt">
        {% if episode.hasSeen == 0 %}
            <input type="checkbox" id="{{ episode.id }}" name="hasSeen" onclick="processForm(this)">
        {% else %}
            <input type="checkbox" id="{{ episode.id }}" name="hasSeen" checked="checked" onclick="processForm(this)">
        {% endif %}
        {{ "E%02d" | format (episode.number) }} - {{ episode.title }}
        {% for i in  1..5 %}
            <span id ="starRating" class="fa fa-star-o" data-rating="{{ i }}" ></span>
            <input type="hidden" name="whatever1" class="rating-value" value="{{ episode.note }}">
        {% endfor %}
    </li>
{% endfor %}

0 个答案:

没有答案