Php 工具提示-刷新div后不起作用

Php 工具提示-刷新div后不起作用,php,jquery,html,ajax,Php,Jquery,Html,Ajax,我请求你的帮助。也就是说,在ajax中与工具提示进行斗争。当页面加载或加载后(如F5),一切工作都非常出色。然而,在part web中,我使用ajax每隔60秒使用一次refresh div <script type="text/javascript" > $.ajaxSetup({ cache: false }); var auto_refresh = setInterval( function() { $('#loaddiv').load('refresh_cluster

我请求你的帮助。也就是说,在ajax中与工具提示进行斗争。当页面加载或加载后(如F5),一切工作都非常出色。然而,在part web中,我使用ajax每隔60秒使用一次refresh div

    <script type="text/javascript" >
$.ajaxSetup({ cache: false });
var auto_refresh = setInterval(
function()
{
$('#loaddiv').load('refresh_clusterdx_2.php');
}, 60000);
</script>

$.ajaxSetup({cache:false});
var auto_refresh=setInterval(
函数()
{
$('#loaddiv').load('refresh_clusterdx_2.php');
}, 60000);
我的工具提示的代码

        <script type="text/javascript">
    $(document).ready(function(){
        function showProfileTooltip(e, id){
            var top = e.clientY -45;
            var left = e.clientX + 25;

            $('.p-tooltip').css({
                'top':top,
                'left':left
            }).show();
            //send id & get info from get_prefix.php
            $.ajax({
                url: '/Info/get_prefix.php?id='+id,
                beforeSend: function(){
                    $('.p-tooltip').html('Loading..');
                },
                success: function(html){
                    $('.p-tooltip').html(html);
                }
            });
        }

        function hideProfileTooltip(){
            $('.p-tooltip').hide();
        }

        $('.profile').mouseover(function(e){
            var id = $(this).attr('data-id');
            showProfileTooltip(e, id);
        });

        $('.p-tooltip').mouseleave(function(){
            hideProfileTooltip();
        });
    });
    </script>

$(文档).ready(函数(){
函数ShowProfile工具提示(e,id){
var-top=e.clientY-45;
左var=e.clientX+25;
$('.p-tooltip').css({
"顶":顶,,
“左”:左
}).show();
//从get_prefix.php发送id和获取信息
$.ajax({
url:'/Info/get_prefix.php?id='+id,
beforeSend:function(){
$('.p-tooltip').html('加载..');
},
成功:函数(html){
$('.p-tooltip').html(html);
}
});
}
函数hideProfileTooltip(){
$('.p-tooltip').hide();
}
$('.profile').mouseover(函数(e){
var id=$(this.attr('data-id');
showProfile工具提示(e,id);
});
$('.p-tooltip').mouseleave(函数(){
hideProfileTooltip();
});
});
所有这些都很漂亮,看起来还不错,直到div没有刷新。当一个div被刷新时,工具提示no work:(我找不到问题的解决方案,是否有可能解决。
谢谢你的帮助。 当做
tjakob

为了确保函数在ajax加载内容后工作,您必须对其进行一些修改:

$(document).on('mouseover', '.profile', function() {
      var id = $('.profile').attr('data-id');
      showProfileTooltip(e, id);
});


$(document).on('mouseleave', '.p-tooltip', function() {
      hideProfileTooltip();
});

对于动态加载的内容,您应该始终使用.on-我现在习惯于对所有函数都这样做。

要确保您的函数在ajax加载内容后工作,您必须稍微修改它们:

$(document).on('mouseover', '.profile', function() {
      var id = $('.profile').attr('data-id');
      showProfileTooltip(e, id);
});


$(document).on('mouseleave', '.p-tooltip', function() {
      hideProfileTooltip();
});

您应该始终在动态加载的内容中使用.on-我现在习惯于在所有功能中使用此选项。

tnx Jason,请回答,但是如果我使用此选项,即使在首次加载页面时,工具提示也不会起作用:(嗯,这对我来说是一个黑魔法,对我来说越来越难以理解,我的脑袋可能已经太老了,不适合这种想法。好的,工具提示使用以下代码:$(document)。on('mouseover','.profile',function(e){var id=$('.profile')。attr('data-id');showProfileTooltip(e,id);};$(document)。on('mouseleave','.p-tooltip',function(){hideProfileTooltip();});但刷新后仍停止工作哇!可以关闭主题!是的,我需要将“.profile”更改为$this,并将工具提示div置于刷新div”之前,向许多TNX Ryan和Jason致意!感谢您的回答!TNX Jason,但如果我使用此修改,工具提示根本不起作用,即使在首次加载页面时:(嗯,这对我来说是一个黑魔法,对我来说越来越难以理解,我的脑袋可能已经太老了,不适合这种想法。好的,工具提示使用以下代码:$(document)。on('mouseover','.profile',function(e){var id=$('.profile')。attr('data-id');showProfileTooltip(e,id);};$(document)。on('mouseleave','p-tooltip',function(){hideProfileTooltip()});但是刷新后仍然停止工作哇工作!!!!主题可以关闭!是的,我需要将“.profile”更改为$this,并将工具提示div放在我们的刷新div'#loaddiv'之前,向许多TNX Ryan和Jason致意!