简体   繁体   中英

how do I check if the stars have been clicked? (Jquery Star rating plugin)

I'm using this plugin http://www.fyneworks.com/jquery/star-rating/#tab-Testing . I was attempting to make a client-side validation system which figures out whether stars have been clicked. I was wondering how you can do it.

In my javascript file, I have

    $('#star1').click(function (){
        document.getElementById('star1').checked=true;
        return false;
    });

I'm using radio button typed stars and have html code like this,

    <input id="star1" name="star1" type="radio" class="star" value="1"/>
    <input id="star1" name="star1" type="radio" class="star" value="2"/>
    <input id="star1" name="star1" type="radio" class="star" value="3"/>
    <input id="star1" name="star1" type="radio" class="star" value="4"/>
    <input id="star1" name="star1" type="radio" class="star" value="5"/>

But this doesn't seem to work.

Working demo http://jsfiddle.net/2xTwb/

Hope it fit your cause :)

scripts

  <script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>

      <script type='text/javascript' src="http://jquery-star-rating-plugin.googlecode.com/svn/trunk/jquery.rating.js"></script>

      <link rel="stylesheet" type="text/css" href="http://jquery-star-rating-plugin.googlecode.com/svn/trunk/jquery.rating.css">

code

$(".voting-star[value='3']").attr("checked", true);

$('.voting-star').rating({
    callback: function(value, link) {
        alert(value);
    }
});
​

You could use .prop method to check the checked property.

$('.star').click(function (){
   if ($(this).prop('checked')) {
     //...
   }
   return false;
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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