Evaluation of star-rated front-end display JS

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.