Implementation: 1, the mouse moves to the third star, then 123 stars lighten, the latter two darken
2, the mouse click on a star, you can continue to choose, but after the stars will hold the position you click
<Scripttype= "Text/javascript"> //★ $(function () { //because it is not good to get the coordinates of the clicked span, declare a variable to record the ID of the clicked span tag varMark; $("*"). css ({margin:"0px", padding:"0px;" }); $("span"). css ({fontSize:"20px", Color:"Yellow"}). MouseOver (function () { $( This). Text ("★"). Prevall (). Text ("★"). End (). Nextall (). Text ("☆"). End (). Click (function() {Mark= $( This). attr ("ID"); }) }); $("Div"). css ({width:"100px", Height:"20px", border:"1px solid Black"}). mouseout (function () { //If you have content in Mark, let the number of stars change back to the location of your most recent click when the mouse leaves the div . if(Mark) {$ ("#" +mark). Text ("★"). Prevall (). Text ("★"). End (). Nextall (). Text ("☆"); } //Mark does not have a value, meaning that you do not click on any star, at this time, so that all the stars are Dim Else { $("span"). Text ("☆"); } }); }); </Script></Head><Body> <DivID= "Div"> <spanID= "1">☆</span><spanID= "2">☆</span><spanID= "3">☆</span><spanID= "4">☆</span><spanID= "5">☆</span> </Div> </Body>
jquery code to achieve a simple five-star evaluation function!