star1.png
This article shares with you the example code of JavaScript to implement the five-star rating function. You can refer to it and learn from it. The specific implementation method is as follows
Before sharing the example code of implementing the five-star evaluation function in JavaScript, let’s take a look at the rendering:
star1.png star1.png
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>53</title> <script src='js/jquery-1.11.1.js'></script> <style> *{ margin: 0; padding: 0; } body{ padding: 20px; } .star1{ width: 70px; height: 13px; background: url('images/star1.png') repeat-x left center; } .star2{ /* width: 60%;*/ height: 13px; background: url('images/star2.png') repeat-x left center; float: left; } </style> <script> $(function(){ var fiveStars=function(num){ if(!num||num<3){ return '--'; } return '<div class="star1"><div class="star2" style="width:'+num*20+'%"></div></div>'; } var str=fiveStars(4) $('body').html(str) }) </script> </head> <body> <!--<div class='star1'><div class="star2"></div></div> --> </body> </html>
I hope this article will be helpful to everyone in learning javascript programming.