jQuery星级插件和jQuery单击功能 [英] jquery star rating plugin and jquery click function

查看:93
本文介绍了jQuery星级插件和jQuery单击功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jquery星级评分插件: http://www.fyneworks. com/jquery/star-rating/

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

我可能会得到一些这样的html代码:

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

我还尝试附加一个ID并使其具有点击功能,但还是没有运气.如果我从按钮中删除star类,那么我的功能将起作用.因此,似乎该插件中的某些代码阻止了外部函数?我需要怎么做才能调用自己的函数?

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?

推荐答案

文档建议您

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

这篇关于jQuery星级插件和jQuery单击功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆