-->

JQuery Star Rating [closed]

2020-01-28 04:07发布

问题:


Want to improve this question? Update the question so it's on-topic for Stack Overflow.

Closed 6 years ago.

Can anyone suggest a simple JQuery five star rating script that is easy to setup. I just need a single instance on a single page. I don't care if it writes to a file or mysql database to calculate rating average.

It should display the number of votes and the calculated average. It should also check if the person has already rated or should not allow more than 2 ratings at a time. Should have cookies or sessions to prevent multiple ratings or some other mechanism.

I don't care if its free or cost money but the licensing should allow me to use it in commercial applications.

Appreciate all suggestions! Thank you!

P.S. I spent a couple of day trying different scripts online but have not found anything that was actually complete.

回答1:

This looks nice:
http://www.fyneworks.com/jquery/star-rating/

But you will need more of a backend to make sure people can't vote twice and to get an average of number of votes. The votes need to be stored somewhere (or at leas the current average) and whether or not a user voted already should be stored on the server too.

This link can tell you about some of the server-side stuff that needs to be done: http://www.yvoschaap.com/index.php/weblog/css_star_rater_ajax_version/



回答2:

I've packaged a star rating plugin for meteor, so I've evaluated all the 11 jQuery rating plugins listed here, and the winner is, by far, RateIt.

Fast, Progressive enhancement, touch support, customizable (just swap out the images, or change some CSS), Unobtrusive JavaScript (using HTML5 data-* attributes), RTL support, supports as many stars as you'd like, and also any step size.

Minified size: 4.35KB (1.55KB when gzipped).

Tested on: IE6-10, Chrome 7-22, Firefox 3.6-16, Opera 10.63-12 - using jQuery 1.6.2 - 1.8.2. Touch support test on iPad iOS 4.2.1-5

RateIt can optionally use the HTML5 range input element - perfect for this purpose. No lame <li> elements or radio buttons.

The others are clearly lesser solutions:

Star Rating, the first answer

  • 78 open issues
  • on Google Code, not on GitHub, which means little to no pull requests
  • latest update 7 months ago

Raty, the second answer

  • somewhat slow development check the issues tab)
  • no mention of browser compatibility or touch support
  • has test suite

https://github.com/ripter/jquery.rating

  • only 22 commits
  • no touch support, browser compatibility listing or anything
  • raty is clearly better

Anyway, none of these mentions browser compatibility or touch support. RateIt does, and it also explains clearly why it's better and different from the others:

Why is RateIt different

Although it does the same job as the rest of the jQuery star rating plugins, the main difference is its simplicity. Most plugins create an element for each (partial) star, be it a div with a star background, or an img tag. Each of these tags gets a hover event, and a click event. And on these hover/click events it has to go and talk to the other stars, telling them to change their state.

So each star plugin does a lot of DOM alterations (adding the number of stars as elements), and adds lots of events (again the number of stars times 2).

RateIt uses basically three divs.

Oh, and the last update? Yesterday.