1

複数の評価が表示されるphpで評価ページを作成するためにjquery rateを使用しています。1つのことがない限り、問題なく動作します。スコア機能、クリック機能は正常に動作します。しかし、各要素のターゲットを設定しようとすると問題が発生します。私が望むのは、各星にカーソルを合わせると評価の選択肢を表示することです。クラス「star_hint」のdivにヒントを表示する必要がありますが、そうではありません。

各要素は、次のように div に表示されます。

<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 を使用できません。スコアやクリックのように、関数内で値を返そうとしましたが、うまくいきません。そのように:

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

誰でもこれを機能させる方法について考えがありますか?

4

2 に答える 2

2

html

<div class="star" data-score="2.6"></div><span class="hint"></span> 

js

$(function () {
     $('div[class^="star"]').each(function(){
        $(this).raty({
            readOnly:true,
            score: function() {return $(this).attr('data-score');},
            }) 
            $(this).next().text($(this).attr('data-score'));
        });
    });
于 2013-10-22T12:25:47.193 に答える