Jquery 悬停事件不工作

Jquery 悬停事件不工作,jquery,html,Jquery,Html,当鼠标悬停在div上时,我试图显示一个delete图标,但悬停事件从不起作用 这是我的密码 此函数用于显示包含数据的div function load_pheeds() { var request_url = url+'pheeds/latest_pheeds'; var timeline = $('#pheed-timeline'); var loading = '<div class="progress-indicator">

当鼠标悬停在div上时,我试图显示一个delete图标,但悬停事件从不起作用 这是我的密码 此函数用于显示包含数据的div

function load_pheeds()
    {
        var request_url = url+'pheeds/latest_pheeds';
        var timeline = $('#pheed-timeline');
        var loading = '<div class="progress-indicator">Loading Pheeds....</div>';
        timeline.append(loading);
        $.ajax({
            url:request_url,
            type:'GET',
            dataType:'json',
            error:function() { },
            success:function(data)
            {
                if(data.message == null)
                {
                    $('.progress-indicator').fadeOut('slow',function() {
                        $.each(data,function(index,pheed)
                        {
                            var del = '';
                            if(pheed.owner == "yes")
                            {
                                del = '<a href="#" class="deletePheed" style="display:none;">Delete Pheed</a>';
                            }
                            timeline.append(
                              '<div class="pheed-holder" data-id="'+pheed.pheed_id+'" data-delete="'+pheed.owner+'">'+
                              '<div class="user-profile-avatar"><img src="'+pheed.avatar_src+'" /></div>'+
                              '<div class="useridentity" data-userid="'+pheed.user_id+'">'+
                              '<a href="'+url+'users/info/'+pheed.username+'">'+pheed.username+'</a>'+
                              '</div>'+del+
                              '<div class="pheedContent">'+pheed.pheed+'</div>'+
                              '<div class="pheedMeta">'+
                              '<span class="timefield t:'+pheed.datetime+'000"></span>'+
                              '<span class="comment-count">'+pheed.comment_count+'</span>'+
                              '</div>'+
                              '</div>'
                            );
                        });
                    });
                }
            }
        });
    }

悬停事件永远不会工作

如果事件的DOM对象是动态的,则需要使用
live
(或1.7中
上的
),而不是
bind

$('div.pheed-holder').live("hover", function() {

您可能需要使用
live
分别绑定到
mouseenter
mouseleave
,而不是使用
hover

尝试绑定事件或使用:

$('div.pheed-holder').live('hover',function(){});

我想你的悬停处理程序在元素被附加之前就被设置好了? 如果执行时不存在
div.pheed-holder
,jQuery无法添加处理程序


尝试在ajax响应后执行
。悬停(…,…)
;请改用
live()

也许您在某个地方遇到了JavaScript错误?您是否已检查以确保锚点实际插入到HTML中?您是否尝试过
$(this)。find(“.deletephed”)
live在1.7中已被删除,您可以改为使用on()
$('div.pheed-holder').live('hover',function(){});