$('.cssraindemo3 tbody tr:even').addClass('odd');
        $('.cssraindemo3 tbody tr').hover(
  function () { $(this).addClass('highlight'); },
  function () { $(this).removeClass('highlight'); }
 );请教下.因为我是动态生成表格的tr和td.所以以上两个语句都无效.请问是否可以live()生成以上语句?

解决方案 »

  1.   

    $(".cssraindemo3 tbody tr").live('hover',
    function() {
    $(this).addClass('highlight');
    },
    function() {
    $(this).removeClass('highlight');
    }
    );$('.cssraindemo3 tbody tr:even').addClass('odd');
    这行代码要在表格结构改变时执行一遍。如果表格一旦生成,结构就不再变化,可以放到$(document).ready() 中执行。
      

  2.   

    不过在jQuery1.7以上版本中已经不赞成使用live()方法来绑定事件了,而是通过新增的on()方法来进行绑定:
    $(".cssraindemo3 tbody tr").on({
    mouseenter: function() {
    $(this).addClass('highlight');
    },
    mouseleave: function() {
    $(this).removeClass('highlight');
    }
    });
      

  3.   

    你好.
    $(".cssraindemo3 tbody tr").live('hover',
        function() {
            $(this).addClass('highlight');
        },
        function() {
            $(this).removeClass('highlight');
        }
    );
    执行后.鼠标离开行后.没有变回原来的样式
      

  4.   

    $(".cssraindemo3 tbody tr").live('hover',
       function() {
       $(this).addClass('highlight');
       },
       function() {
    alert('aa');
       $(this).removeClass('highlight');
       }
    );
    这样看看执没执行下面的方法
      

  5.   

    on()绑定的代码我也写错了。。
    $("body").on({
        mouseenter: function() {
            $(this).addClass('highlight');
        },
        mouseleave: function() {
            $(this).removeClass('highlight');
        }
    }, ".cssraindemo3 tbody tr"
    );
      

  6.   


    应该不是JS代码的问题,估计是样式的问题,.highlight类下面有没有定义子类?
      

  7.   

    用原来的方法
    $('.cssraindemo3 tbody tr').hover(
      function () { $(this).addClass('highlight'); },
      function () { $(this).removeClass('highlight'); }
     );
    鼠标离开后.tr能还原原来的样式.但用了LIVE()之后.好象只执行第一个function,第二个function没有执行.
      

  8.   

    这个不懂了。你用的jQuery版本是多少?
      

  9.   

    http://stackoverflow.com/questions/2262480/jquery-live-hover
    看这个