weixin_33725807 2009-07-26 14:42 采纳率: 0%
浏览 23

jQuery粘贴显示:块

I have a message board, and I have some code that loads new messages automatically as they arrive. I have, addtionally, the following code run on all board posts.


$(".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();
        });

All the new posts don't get this hover effect, even though they belong to the same class. In addtion, while all the posts that are NOT loaded via AJAX have the following div:

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

the new posts have

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

the function that generates the posts on the server-side the the same.

Any help on this? (How can I get the AJAX-ed posts to have a onHover effect?)

  • 写回答

1条回答 默认 最新

  • weixin_33709609 2009-07-26 14:46
    关注

    You must use live to bind an event (docs here). Unfortunately live doesn't support hover so you have to split your code and define mouseover and mouseout event handlers.

    $(".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();
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元