2013-02-12 49 views
3

我正在使用jQuery Raty插件這是一個星級評級插件,它的ss工作正常。如何獲得jQuery Raty中選定的星號值

這裏是我的代碼

$('#star').raty({ 
      path: '/Content/RatingPlugin/', 
      numberMax: 5, 
      score: function() { 
       return $(this).attr('data-score'); 
      } 
     }); 

HTML

<div id="star" data-score="@Model.Company.Rating"></div> 

現在有2個問題,想在我的網頁加載@Model.Company.Rating值是4它會顯示4星上是正確的,但如果任何一個點擊第三顆星星,它將關閉那顆第四顆星星,然後只有3顆星星將會亮起。我想,如果用戶點擊任何明星,然後在JavaScript中,我得到的明星的價值,並將其存儲在數據庫,但它不應該對用戶端的影響我的意思是點擊用戶數量on stars後將保持不變。

如果您需要任何其他細節,請讓我知道。

+0

http://wbotelhos.com/raty/#readOnly-callback – 2013-02-12 07:31:22

回答

4

http://jsfiddle.net/DerekL/bp2mW/18/

$('#star').raty({ 
    score: 3,             //default score 
    starOn: "http://wbotelhos.com/raty/lib/img/star-on.png", 
    starOff: "http://wbotelhos.com/raty/lib/img/star-off.png", 
    readOnly: true            //read only 
}); 

$("#star > img").click(function(){ 
    var score = $(this).attr("alt");        //record clicked 
    alert(score);            // value of the 
    //save to database            star 
}); 

瞭解更多關於readonlyplugin's docs

6

對象初始化後,您可以撥打.raty('score')獲取分數的值。如果未設置,該值將不確定。

var currentScore = $('#star').raty('score'); 

文檔:http://wbotelhos.com/raty#functions