我正在使用 jQuery 评级 plugin我无法将成功消息显示到相应的 div 中,因为 $(this) 不引用选择器而是返回 Object 对象。
这是我的代码:
$(".basic").jRating({
bigStarsPath: 'assets/stars.png',
rateMax: 5,
length : 5,
phpPath : '<%= Rails.application.class.routes.url_helpers.ratings_path %>',
onSuccess : function(){
$(this).find(".message").append('<small>Thanks for your vote!</small>');
}
});
所以问题是 $(this) 不引用 $(".basic") 我想知道如何访问插件中的选择器。 我很确定这可能是一个新问题,但我的 javascript 技能根本不广泛。 预先感谢您。
最佳答案
关于jRating源码code line将传递给 onSuccess 和 onError 处理程序的参数是 element 和 rating,因此解决方案是:
$(".basic").jRating({
bigStarsPath: 'assets/stars.png',
rateMax: 5,
length : 5,
phpPath : '<%= Rails.application.class.routes.url_helpers.ratings_path %>',
onSuccess : function(element /*, rating */){
$(element).find(".message").append('<small>Thanks for your vote!</small>');
}
});
关于javascript - 如何使用 jQuery 插件访问 $(this),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14941828/