jquery star rating plugin and jquery click functio

2019-03-02 02:55发布

I'm using the jquery star rating plugin: http://www.fyneworks.com/jquery/star-rating/

I might get some html code like this:

<form name="api-disable">
  <input type="radio" class="star {split:2}" name="api-readonly-test" value="1"/>
  <input type="radio" class="star {split:2}" name="api-readonly-test" value="2"/>
  <input type="radio" class="star {split:2}" name="api-readonly-test" value="3"/>
  <input type="radio" class="star {split:2}" name="api-readonly-test" value="4"/>
  <input type="radio" class="star {split:2}" name="api-readonly-test" value="5"/>
  <input type="radio" class="star {split:2}" name="api-readonly-test" value="6"/>
  <input type="radio" class="star {split:2}" name="api-readonly-test" value="7"/>
  <input type="radio" class="star {split:2}" name="api-readonly-test" value="8"/>
  <input type="radio" class="star {split:2}" name="api-readonly-test" value="9"/>
  <input type="radio" class="star {split:2}" name="api-readonly-test" value="10"/>
  <input type="button" value="Submit &raquo;" onClick="
   $(this).next().html( $(this.form).serialize() || '(nothing submitted)' );
  "/>
  <span></span>
 </form>

This works fine, but if I try to call my own function my function doesn't alert. For example:

$('.star').click( function () {
    alert('test');
});

I also tried attaching an id and making that the click function, but still no luck. If I remove the star class from the buttons then my function will work. So it seems some of the code in this plugin prevents outer functions? What would I need to do to call my own function?

1条回答
男人必须洒脱
2楼-- · 2019-03-02 03:08

The documentation suggests you can add a click callback, as well as some other events, when you activate that plugin:

$('.auto-submit-star').rating({ 
  callback: function(value, link){ 
   alert(value); 
  } 
});
查看更多
登录 后发表回答