Rating by jquery rating (excellent Version)

Source: Internet
Author: User
Document directory
  • Rating. js code:
  • Page code:

Functions:

  1. Multiple stars can be used on the same page without interfering with each other.
  2. The number of stars can be customized.
  3. You can set the default star rating.
  4. After selecting a star, there is still a hover Effect
  5. Customizable star rating description
Rating. js code:

Function initstar (count, cur, S0, S1, CTN, txt) {for (VAR I = 1; I <= count; I ++) {var P = (I <= cur )? S1: S0; $ (" "). ATTR ({"src": P, "flag": I }).css ("cursor", "Pointer "). mouseover (function () {var cur = parseint ($ (this ). ATTR ("flag"); $ ("#" + CTN ). children (). each (function () {var I = parseint ($ (this ). ATTR ("flag"); var P = (I <= cur )? S1: S0; $ (this ). ATTR ("src", P) ;}); showstar (txt, cur );}). click (function () {// original blog: blog.csdn.net/bluceyoung $ ("#" + CTN ). ATTR ("Star", $ (this ). ATTR ("flag "));}). appendto ($ ("#" + CTN);} $ ("#" + CTN ). ATTR ("Star", cur ). mouseout (function () {var cur = parseint ($ (this ). ATTR ("star"); $ (this ). children (). each (function () {var P = ($ (this ). ATTR ("flag") <= cur )? S1: S0; $ (this ). ATTR ("src", P) ;}); showstar (txt, cur) ;});} function showstar (txt, cur) {$ ("#" + txt ). val (cur); $ ("#" + txt ). change ();}

Parameter description:

Count: Total number of stars
Cur: the number
S0: Image path of empty stars
S1: Image path of real stars
CTN: Create a Star Container
TXT: textbox that displays the rating description

Page code:

<HTML> <SCRIPT src = "http://code.jquery.com/jquery-1.8.2.min.js" type = "text/JavaScript"> </SCRIPT> <SCRIPT src = "rating. JS "type =" text/JavaScript "> </SCRIPT> <SCRIPT type =" text/JavaScript ">$ (document ). ready (function () {// create star initstar(5,3,'k.gif ', 's.gif', 'lblstar1', 'txt ') // rewrite the star description $ ("# TXT "). change (function () {var v = $ (this ). val (); Switch (v) {Case "1": V = "too bad"; break; Case "2": V = "to be improved"; break; case "3": V = "general"; break; Case "4": V = "good"; break; Case "5": V = "great "; break; default: V = "" ;}$ (this ). val (v );});}); </SCRIPT> <body> <label id = "lblstar1"> </label> <input type = "text" id = "TXT"> <br> </body> 

By default, only the number of rating levels is displayed in the textbox of the rating description. to customize the rating description, add a change event and replace the value in it.

:

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.