此问题与this之一有关。 我使用Tooltipster JQuery插件在我的网站上显示工具提示,如:
HTML
ng-repeat
JS
<div class="tooltip" data-id="'.$comment['id'].'">Hover me!</div>
无论如何,这并不适用于Ajax动态内容,基本上我通过Ajax新内容加载了一个函数:
<script type="text/javascript">
$(document).ready(function() {
$('.tooltip').tooltipster({
content: 'Loading...',
functionBefore: function(instance, helper){
var $origin = $(helper.origin);
$.ajax({
type: "POST",
url: baseUrl+"/requests/load_profilecard.php",
data: 'id='+ $origin.attr('data-id')+"&token_id="+token_id,
cache: false,
success: function(html) {
// call the 'content' method to update the content of our tooltip with the returned data
instance.content(html);
}
});
},
interactive:true,
contentAsHTML:true,
maxWidth:250
});
});
</script>
鼠标悬停的新内容不显示任何工具提示,从控制台我看不到任何错误或警告,并且未在网络function exploreTracks(start, filter) {
$('#load-more').html('<div class="load_more" style="height: 232px;"><div class="preloader-loadmore preloader-center"></div></div>');
if(filter == '') {
q = '';
} else {
q = '&filter='+filter;
}
$.ajax({
type: "POST",
url: baseUrl+"/requests/load_explore.php",
data: "start="+start+q+"&token_id="+token_id,
cache: false,
success: function(html) {
$('#load-more').remove();
// Append the new comment to the div id
$('#main-content').append(html);
// Reload the timeago plugin
jQuery("div.timeago").timeago();
// Update the Track Information
updateTrackInfo(nowPlaying);
}
});
}
上调用。
我已将脚本(与上面相同的JS)直接放在我的内容页面上,那么为什么鼠标悬停时不会显示工具提示?
我的解决方案
正如Evan的评论中所建议我为此目的使用delegation选项。
load_profilecard.php