简体   繁体   English

将rateit jquery插件应用于选择框

[英]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表单元素,我想将rateit jquery插件应用于它。

<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(); 我试图使用$("select.test").rateit();来应用插件$("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. ,但尽管fireQuery显示数据附加了select元素,没有效果,我仍然留下一个选择框,而不是一行星。

EDIT 编辑

CSS File is included 包含CSS文件

Here is the page in question 这是有问题的页面

You're using the plugin wrong. 你使用的插件错了。 See very simple example: http://jsfiddle.net/rudiedirkx/ZuJ2k/ 看一个非常简单的例子: 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(); select必须在那里,但是你在调用插件时仍然需要引用div$('div#rating2').rateit();

The div then has a reference to the select with a data attribute: data-rateit-backingfld="select#Rating" 然后div使用data属性引用selectdata-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. 在最后一行,您引用div#rateit ,但该div不存在。 You just created a div.rateit , not a div#rateit . 你刚刚创建了一个div.rateit ,而不是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(); 只需打开您的Javascript控制台(FF中的Firebug或Chrome中的开发人员工具)并输入: jQuery('div.rateit').rateit();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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