jquery粘贴显示:块

时间:2009-07-26 14:42:25

标签: php jquery ajax

我有一个留言板,我有一些代码可以在到达时自动加载新消息。 另外,我还有以下代码在所有主板帖子上运行。


$(".old_post").hover(function(){
            $(".post_right_nav", this).show();
            $(this).css({
                'background-color': '#E6E6E6'
            });
        }, function(){
            var cssObj = {
                'background-color': '',
                'font-weight': ''
            }
            $(this).css(cssObj);
            $(".post_right_nav", this).hide();
        });

所有新帖都没有获得此悬停效果,即使它们属于同一个类。 另外,虽然所有未通过AJAX加载的帖子都有以下div:

<div id="id_number" class="old_post" style="">

新帖子

<div id="id_number" class="old_post" style="display: block;">

在服务器端生成帖子的功能相同。

对此有何帮助? (如何让AJAX编辑的帖子具有onHover效果?)

1 个答案:

答案 0 :(得分:1)

您必须使用live绑定事件(docs here)。遗憾的是live不支持悬停,因此您必须拆分代码并定义mouseovermouseout事件处理程序。

$(".old_post").live('mouseover', function() {
    $(".post_right_nav", this).show();
    $(this).css({
        'background-color': '#E6E6E6'
    });
});

$(".old_post").live('mouseout', function(){
    var cssObj = {
        'background-color': '',
        'font-weight': ''
    }
    $(this).css(cssObj);
    $(".post_right_nav", this).hide();
});