Star rating of five stars:
Description: The hypothesis is to use three kinds of pictures to display star rating, that is 1. Bright Star 2. Half-bright stars 3. Stars that are not bright;
The full score is 5 points; (here of course it can be variable as a parameter
The function passed in parameter grade represents the current score.
functionStar_show (grade) {varStar = 0,//number of stars litHalf = 0,//half-Bright Star 1 is half the caseNostar = 0;//number of stars not litGrade =parsefloat (grade); if(IsNaN (grade) | | Grade <= 0) grade = 0; if(Grade > 5) Grade = 5; Star=parseint (grade); //at least one is here, depending on the situation. if(star = = 0) Star = 1; //indicates that there are half stars if(Grade-star > 0) Half = 1; //number of non-brightNostar = 5-star-half; varPath = "imgs.example.com/",//Picture Master Pathstar_img = path + "Ok-xing.png",//Full star image addresshalf_img = path + "Nk-xing.png",//Half star Picturenostar_img = path + "No-xing.png",//non-illuminated image addresshtml = ';//method returns the HTML //Full Star for(vari=0; i< Star; i++) {HTML+ = ' '; } //Half Star if(Half = = 1) {HTML+ = ' '; } //The star is not bright for(varj=0; J < Nostar; J + +) {HTML+ = ' '; } returnhtml; }
Evaluation of star-rated front-end display JS