简体   繁体   中英

Applying rateit jquery plugin to a select box

I have the following select form element, and I want to apply the rateit jquery plugin to it.

<select class="test" id="Rating" name="Rating">
  <option value="1">1</option>
  <option value="2">2</option>
  <option value="3">3</option>
  <option value="4">4</option>
  <option value="5">5</option>
</select>

and I am trying to apply the plugin using $("select.test").rateit(); , but despite fireQuery showing data attached the the select element that, no effect is made and I am still left with a select box, and not a line of stars.

EDIT

CSS File is included

Here is the page in question

You're using the plugin wrong. See very simple example: http://jsfiddle.net/rudiedirkx/ZuJ2k/

The select has to be there, but you still have to reference the div when you call the plugin: $('div#rating2').rateit();

The div then has a reference to the select with a data attribute: data-rateit-backingfld="select#Rating"

edit
Actually it looks like you're not using the plugin at all? Where do you call the plugin?

edit
This is your code:

rateItDiv = $('<div class="rateit" data-rateit-backingfld="#Rating"></div>');
$("div#ReviewInputZone select.test").after(rateItDiv);
$('div#rateit').rateit();

On the last line, you reference div#rateit , but that div doesn't exist. You just created a div.rateit , not a div#rateit . Change either of those to the other, and it should work. I'd keep the # because that's slightly faster (but you'd have to be sure there's only one of these rateit dropdowns on a page).

So the new first line:

rateItDiv = $('<div id="rateit" class="rateit" data-rateit-backingfld="#Rating"></div>');

edit
Also, you can test it before you change any code. Just open your Javascript console (Firebug in FF or Developer tools in Chrome) and type: jQuery('div.rateit').rateit();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM