3

我正在使用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>

现在有两个问题,假设当我的页面加载@Model.Company.Rating值是4它会显示 4 颗星,哪个是正确的,但是如果有人点击第三颗星,它将关闭第 4 颗星,然后只有 3 颗星会亮。我希望如果用户单击任何星,然后在 javascript 中我得到该星的值并将其存储在数据库中,但它不应该对用户产生影响,我的意思是在单击用户数量on stars后将保持不变。

如果您需要任何其他详细信息,请告诉我。

4

2 回答 2

6

初始化对象后,您可以调用.raty('score')以获取分数的值。如果未设置,则该值将是未定义的。

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

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

于 2015-06-03T15:07:33.780 回答
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
});

了解有关readonly插件文档的更多信息。

于 2013-02-12T07:45:00.217 回答