star1.png  
Home > Web Front-end > JS Tutorial > body text

Javascript implements five-star rating function_javascript skills

WBOY
Release: 2016-05-16 15:33:00
Original
1886 people have browsed it

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>
Copy after login

I hope this article will be helpful to everyone in learning javascript programming.

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!