The code in JavaScript
var spans=document.getelementsbytagname ("span");
var flag=5;//this value randomly, as long as it's not 01234.
var expand=function () {
Extension code, no
};
Onload=function () {
Looping the mouse-over event into the load
for (Var i=0;i<spans.length;i++) {
Spans[i].onmouseover=function () {
var id=parseint (this.id);
for (Var i=0;i<=id;i++) {
Spans[i].innerhtml= "★";
}
for (Var j=id+1;j<5;j++) {
Spans[j].innerhtml= "☆";
}
};
}
Loop load mouse click Star Event
for (Var i=0;i<spans.length;i++) {
Spans[i].onclick=function () {
var id=parseint (this.id);
Flag=id;
for (Var i=0;i<=id;i++) {
Spans[i].innerhtml= "★";
}
Expand ();//Here is the mouse click on the star expansion, such as the occurrence of scores, etc., in short, to expand what with your stool and urine ~
};
}
Load Mouse away div event
document.getElementById ("div"). Onmouseout=function () {
If the tag is 3, the loop gives 0 1 2 3 A few stars to the whole yellow
if (flag>=0 && flag<=4) {
for (Var i=0;i<=flag;i++) {
Spans[i].innerhtml= "★";
}
for (Var j=flag+1;j<5;j++) {
Spans[j].innerhtml= "☆";
}
}
If the tag does not have a value or is the initial 5, then all the stars will be restored to empty stars.
else{
for (Var i=0;i<spans.length;i++) {
Spans[i].innerhtml= "☆";
}
}
};
};
The code in the body
<div id= "div" >
<span id= "0" >☆</span><span id= "1" >☆</span><span id= "2" >☆</span><span id= "3" >☆</span><span id= "4" >☆</span>
</div>
JavaScript code to achieve a simple five-star evaluation function!