JavaScript to make Taobao star scoring effect of thinking _javascript skills

Source: Internet
Author: User

Small set is also just beginning to learn JavaScript, think that Taobao evaluation of the star effect is very good, so produced their own to write an idea, first to share the implementation of the results:

I am enclosing the source code I wrote.

<! DOCTYPE html>  

The first two for loops are like this:

 for (Var i=0;i<=n;i++)
   {
    document.getElementById ("Fivestar"). innertext= "★";
   }
   for (Var j=4;j>n;j--)
   {
    document.getElementById ("Fivestar"). innertext= "☆";
   

The great gods have already figured out that the span in the HTML after the For loop has lost its effect, meaning it can only be evaluated once ...
So along this train of thought to solve this problem with an array, that is, let the evaluation star effect of each star stored in the array, wrote the above code, but also made a small landlord, really trapped annoyed for a long time ....
Array[0]=document.getelementbyid ("Onestar"). innertext;
Arrays defined by this .... As it turns out, the following code simply cannot change the rating, and then realizes that this definition directly assigns the contents of the element with ID Onestar to the array, which means that the number consists of a pointer to the array .... Naturally, you cannot change the value of the corresponding element. Then finally understand ....
And then added some CSS effects.
The finished product is like this:

<! DOCTYPE html>  

Above is JavaScript to make Taobao star rating effect of ideas, language is straightforward, easy to understand, I hope to help you learn, and small together to explore JavaScript more magical place, common progress.

Related Article

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.