【问题标题】:jquery affixing display: blockjquery 附加显示:块
【发布时间】:2009-07-26 14:42:25
【问题描述】:

我有一个留言板,我有一些代码可以在新消息到达时自动加载它们。 此外,我在所有董事会帖子上运行了以下代码。


$(".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-ed 帖子具有 onHover 效果?)

【问题讨论】:

    标签: php jquery ajax


    【解决方案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();
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多