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.
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:
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.