jquery star rating plugin and jquery click function

我们两清 提交于 2019-12-02 09:27:06

问题


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:


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); 
  } 
});


来源:https://stackoverflow.com/questions/1547120/jquery-star-rating-plugin-and-jquery-click-function

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