简体   繁体   English

使用jquery rateit插件从星星中获取选定的值

[英]to get selected value from stars using jquery rateit plugin

I am using rateit plugin of jQuery for star rating. 我正在使用jQuery的Rateit插件进行星级评分。 here is the plugin http://rateit.codeplex.com/ 这是插件http://rateit.codeplex.com/

My code: 我的代码:

<link href="rateit.css" rel="stylesheet" type="text/css">
<script src="../src/jquery.rateit.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" type="text/javascript"></script>

<div class="rateit" id="rateitval" data-rateit-step="1" data-rateit-resetable='false'></div>

<input type="button" onclick="dis();">

<script type="text/javascript">
    var tooltipvalues = ['bad', 'poor', 'ok', 'good', 'super'];
    var v = 1;
    $("#rateitval").bind('over', function(event, value) {
        v = value;
        $(this).attr('title', tooltipvalues[value - 1]);
    });

    function dis() {
        alert(v);
    }
</script>

I need to get the rate value given in the star as an alert when i click the button. 单击按钮时,我需要获得星号中给出的比率值作为警报。 But for my code, it shows me null for all values. 但是对于我的代码,它向我显示所有值均为null。 Suggest me some solutions. 向我建议一些解决方案。

Try this,it worked for me 试试这个,对我有用

<script type="text/javascript">
    $("#rateitval").click(function () {

        var x = $(this).rateit('value');
        console.log(x);
    });
</script>

I Find Cool and simple way to get value from RateIt stars. 我发现从RateIt明星那里获得价值的酷而简单的方法。

I show you code example: 我向您展示代码示例:

HTML View: HTML视图:

<span id="RateForm_15" class="rateit"></span> // I give rate span unique ID

Jquery Script: jQuery脚本:

var rateValue = $('#RateForm_15 > div').attr('aria-valuenow'); //hare is a value

Suppose following is your html: 假设以下是您的html:

  <div class="rateit bigstars" data-rateit-starwidth="32" data-rateit-starheight="32" data-value="0.0" data-step="1.0" data-rateit-min="0" data-rateit-max="5" id="customer_rating"></div

get selected value: 得到选择的值:

$('#customer_rating').rateit('value');

set value: 设定值:

$('#customer_rating').rateit('value', 2)

reset: 重启:

 $('#customer_rating').rateit('reset');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM