我有一些 jQuery,它在悬停时为 > 标签的背景颜色设置动画<div
(并在不再悬停时恢复它们)。
$('.row').hover(function() {
$(this).stop().animate({
backgroundColor: "#000000"
}, 250 );
}, function () {
$(this).stop().animate({
backgroundColor: "#15181A"
}, 250 );
});
我的页面上有一个 AJAX 调用来加载一些额外<div
的 >,如下所示:
$.ajax({
type : 'POST',
url : "ajax.php",
dataType : 'json',
data: {
query : $('#search').val()
},
success : function(data) {
if (data.error === true) {
// Error
} else {
$('#more').html(data.msg);
}
},
error : function(XMLHttpRequest, textStatus, errorThrown) {
// Error
}
});
AJAX 调用有效地返回更多<div
带有“行”类的 >s,但是当它们悬停时,jQuery 不会为其背景颜色设置动画。是否可以使用 jQuery 选择这些行,即使它们是通过 AJAX 加载的?
编辑:这是 AJAX 调用 ajax.php 返回的内容:
<?php
$return['error'] = false;
$return['msg'] = '<div class="row" style="background: #15181A;">A row...</div>';
$return['msg'] = '<div class="row" style="background: #15181A;">Another row...</div>';
$return['msg'] = '<div class="row" style="background: #15181A;">Another row...</div>';
echo json_encode($return);
return;
?>