Jquery星级评级插件的十进制评级

时间:2012-11-30 12:21:49

标签: jquery rating

我正在使用来自http://www.fyneworks.com/jquery/star-rating/#tab-Testing的jquery星级评分插件。我想对我的应用程序使用十进制星级评级。所以我正在使用

  

Test4半星和分裂星

html代码如下。

<input class="star {split:2}" type="radio" value="0.5" name="test-4-rating-3" />
<input class="star {split:2}" type="radio" value="1.0" name="test-4-rating-3" />
<input class="star {split:2}" type="radio" value="1.5" name="test-4-rating-3" />
<input class="star {split:2}" type="radio" value="2.0" name="test-4-rating-3" />
<input class="star {split:2}" type="radio" value="2.5" name="test-4-rating-3" />
<input class="star {split:2}" type="radio" value="3.0" name="test-4-rating-3" />
<input class="star {split:2}" type="radio" value="3.5" name="test-4-rating-3" />
<input class="star {split:2}" type="radio" value="4.0" name="test-4-rating-3" />
<input class="star {split:2}" type="radio" value="4.5" name="test-4-rating-3" />
<input class="star {split:2}" type="radio" value="5.0" name="test-4-rating-3" />

脚本如下。

$('.star').rating({
       split: 2, 
       callback: function(value, link){
           alert(value);          
       }
   });

请建议我如何使用{split:2}以及如何在点击星星时获得额定值。这项工作将更加令人赞赏。

2 个答案:

答案 0 :(得分:1)

所以我在黑暗中开枪,因为你联系的网站不是很清楚,但这就是我得到的。

  1. 根据该网站,您需要使用特殊metadata plugin来使分割工作。可能在星形插件之前在HTML中包含此文件。
  2. 据我所知,他们只是更新了表单元素的value属性,因此您可以像$(".star").val()一样访问该值,但正如您所说,您希望在单击时看到该值关于这件事,你必须遵循他们的指示。
  3. 您确定将JS包装在$(function() { });中还是将JS放在页面的末尾?
  4. 此插件似乎非常过时。我知道该网站提到了最近的更新,但代码质量和链接意味着它已有几年的历史了。我强烈建议您为明星使用更现代的jquery插件,例如github上的几个插件。看看Raty似乎有不错的文档。

答案 1 :(得分:0)

@Jamund的链接不再有效了。它现在似乎在这里。

https://github.com/jquery-orphans/jquery-metadata

我用它,它对我有用。