Jquery星级评分插件和取消评分按钮
使用此插件: http://www.fyneworks.com/jquery/star - rating/#tab-Testing
我有一个简单的回调函数,可以从单选按钮中获取 id:
<input type="radio" class="auto-submit-star {split:2}" id="myid" value="1" />
$('.auto-submit-star').rating({
callback: function(value, link){
alert($(this).attr('id'));
}
});
这工作正常,但是如果用户单击取消按钮,则它无法读取它。
在js中,我认为取消按钮是动态添加的:
control.cancel = $('<div class="rating-cancel"><a title="' + control.cancel + '">' + control.cancelValue + '</a></div>')
如果我像这样添加一个id:
control.cancel = $('<div class="rating-cancel"><a id="someid" title="' + control.cancel + '">' + control.cancelValue + '</a></div>')
我怎样才能读取id?这将是未定义的。我可以设置一个类并使用 $('.myclass').attr('id') 但我将在一页上有多个评级,因此我需要类似于“this”的内容。或者取消按钮是否可以获取相应单选按钮的 id?
Using this plugin: http://www.fyneworks.com/jquery/star-rating/#tab-Testing
I have a simple callback function that picks up the id from the radio buttons:
<input type="radio" class="auto-submit-star {split:2}" id="myid" value="1" />
$('.auto-submit-star').rating({
callback: function(value, link){
alert($(this).attr('id'));
}
});
This works fine, but if the user clicks on the cancel button, then it can't read the id of it.
In the js, I think the cancel button is added dynamically with:
control.cancel = $('<div class="rating-cancel"><a title="' + control.cancel + '">' + control.cancelValue + '</a></div>')
If I add an id to it like this:
control.cancel = $('<div class="rating-cancel"><a id="someid" title="' + control.cancel + '">' + control.cancelValue + '</a></div>')
How could I read the id? This would be undefined. I can set a class and use $('.myclass').attr('id') but I will have multiple ratings on one page so I'll need something similar to "this". Or is it possible for the cancel button to pick up the id of the corresponding radio buttons?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果
id
未定义,那么您就知道他们单击了取消按钮。无需为其设置id
。If the
id
is undefined, then you know they clicked the cancel button. No need to set anid
for it.好吧,罗杰 - 我发现这个是因为我面临着同样的问题。我暂时是这样解决的。我确实希望该插件将来得到修复。我的感觉是,您此时不需要解决问题,但它可能会帮助其他人。显然,它依赖于 DOM 元素的结构,因此不是一个非常优雅的解决方案。
Ok Roger - I found this because I was facing the same EXACT issue. Here is how I solved it for the time being. I do hope the plugin gets fixed in the future. My sense is that you don't need the issue resolved at this point, but it may help out other folks. Obviously, it relies on structure of the DOM elements, hence not a very elegant solution.
谢谢瑞安!我将点击事件添加到了对我有用的评级取消类中
Thanks Ryan! I added the click event to rating-cancel class which worked for me
这是插件中的一个错误。
此处已修复。
This is a bug in the plugin.
There's a fix here.