to get selected value from stars using jquery rateit plugin

放肆的年华 提交于 2019-12-11 20:15:18

问题


I am using rateit plugin of jQuery for star rating. here is the plugin 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. Suggest me some solutions.


回答1:


Try this,it worked for me

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

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



回答2:


I Find Cool and simple way to get value from RateIt stars.

I show you code example:

HTML View:

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

Jquery Script:

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



回答3:


Suppose following is your 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');


来源:https://stackoverflow.com/questions/28240064/to-get-selected-value-from-stars-using-jquery-rateit-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!