如何在多jQuery Raty系统中控制目标 [英] how to control target in a multiple jquery raty system

查看:114
本文介绍了如何在多jQuery Raty系统中控制目标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jquery raty在php中创建一个评分页面,其中显示了多个评分.除非有一件事情,否则一切正常.得分功能和点击功能都可以正常运行.但是我在尝试为每个元素设置目标时遇到了问题.我想要的是显示悬停在每颗星上的评级选择.它应该在类为"star_hint"的div中显示提示,但事实并非如此.

I'm using jquery raty to do a rating page in php, where multiple rating are displayed. It works ok unless one thing. The score function, and the click function works ok. But I'm having problems trying to set the target for each element. What I want is to show the rating choice on hover over each star. It should show the hint in the div with class "star_hint", but it isn't.

每个元素都显示在div中,如下所示:

Each element is displayed in a div like this:

<div class="span4">
   <h4>First valoration</h4>
   <div class="star" data-number="3"></div>                                         
   <input type="hidden" class="score_value" />                                  
   <div class="star_hint"></div>
</div>

<div class="span4">
   <h4>Second valoration</h4>
   <div class="star" data-number="4"></div>                                         
   <input type="hidden" class="score_value" />                                  
   <div class="star_hint"></div>
</div>
etc....

脚本是这样的:

$('.star').raty({
    target: $(this).next('.star_hint'),
    score: function() {
        return $(this).attr('data-number');  // set default value 
    },
    click: function(score) {
        $(this).next().val(score);  // save clicked value in hidden input
        GetAverageNote();  // calculates average note from all ratys
    }
});

我不能将id用作目标,因为每个星项都有一个不同的目标.我试过也返回一个函数中的值,如得分和点击,但它不起作用. 像这样:

I can not use an id for target, because each star item has a different target. I tried also return the value within a function, like score and click does, but it doesn't worked. Like that:

target: function() {
    $(this).next('.star_hint');
   }

有人对如何使这项工作有想法吗?

Anyone have an idea on how to make this work?

推荐答案

您可以遍历需要绑定raty()方法的所有spandiv,然后将tid作为变量传递设置raty({target:tid})

You can loop thru all the span or divs for which raty() method needs to be bound and then pass tid as a variable to set raty({target:tid})

Rate <span id="star_xxx" data-number="3" rel="#hint_xxx" ></span>  <span  id="hint_xxx">   </span>

$( document ).ready(function() {
$('span[id^="star"]').each(function(){
    var tid = $(this).attr('rel'); 
    $(this).raty({
        target : tid ,
        starOff : '/img/star-off.png', 
        starOn : '/img/star-on.png'     

}) 
}) 


});

这篇关于如何在多jQuery Raty系统中控制目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆