我已经尝试了很长时间了,以使尼克·萨卢姆(Nick Salloum)的这5个星级评分控件正常工作:
http://callmenick.com/post/five-star-rating-component-with-javascript-css

这是我的尝试:https://jsfiddle.net/n6qzkpcy/2/

谁能看到我做错了什么,因为它没有显示任何星星?

// target element
var el = document.querySelector('#el');

// current rating, or initial rating
var currentRating = 0;

// max rating, i.e. number of stars you want
var maxRating= 5;

// callback to run after setting the rating
var callback = function(rating) { alert(rating); };

// rating instance
var myRating = rating(el, currentRating, maxRating, callback);

最佳答案

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Five Star Rating</title>
  <link rel="stylesheet" href="css/font-awesome.min.css">
  <link rel="stylesheet" href="css/style.min.css">
  <link rel="stylesheet" href="css/rating.min.css">
</head>
<body>

<ul class="c-rating" id="el">

</ul>

<script src="js/dist/rating.min.js"></script>
<script type="text/javascript">
    var el = document.querySelector('#el');

    // current rating, or initial rating
    var currentRating = 1;

    // max rating, i.e. number of stars you want
    var maxRating= 5;

    // callback to run after setting the rating
    var callback = function(rating) { alert(rating); };

    // rating instance
    var myRating = rating(el, currentRating, maxRating, callback);

</script>
</body>
</html>


请使用上面的HTML页面,并放置从git下载的所需资源。您会看到结果。

08-27 18:03