我有一个raty div的页面。使用经典代码$('.raty').raty({...});
,插件可以在这些现有的div上完美运行。但是当我通过ajax函数加载新的raty div时,新的div“没有变成星星”。你能帮我找到我的错误吗?
$.ajax({
url: '/ws/player/reviews/p/1',
context: document.body,
contentType: "application/json; charset=utf-8",
dataType: "jsonp",
jsonp: "callback",
jsonpCallback: "jsonpCallbackfunction",
success: function(data) {
$.each(data.response.reviews, function( key, value ) {
html = '';
html += '<div class="raty read" data-rating="5"></div>';
$('#reviews').append(html);
});
}
data: {player_id: player_id, from: $('#reviews').data('from')}
}).done(function() {
$(this).find('.raty').raty({
path: '/img/raty/',
readOnly: true,
score: function() {return $(this).data('rating');}
});
});
虽然,如果我尝试$(this).find('.raty').html('blablabla');
“blablabla”正确地写在我的所有'.raty'div中。
谢谢你的帮助,
杰里米
答案 0 :(得分:1)
你没有犯错误
$.ajax({
url: '/ws/player/reviews/p/1',
context: document.body,
contentType: "application/json; charset=utf-8",
dataType: "jsonp",
jsonp: "callback",
jsonpCallback: "jsonpCallbackfunction",
success: function(data) {
$.each(data.response.reviews, function( key, value ) {
html = '';
html += '<div class="raty read" data-rating="5"></div>';
$('#reviews').append(html);
});
}
data: {player_id: player_id, from: $('#reviews').data('from')}}).done(function() {
$(this).find('#reviews .raty').raty({ // Changes
path: '/img/raty/',
readOnly: true,
score: function() {return $(this).data('rating');}
});});
希望,此代码可以正常工作