【问题标题】:jQuery: Replacing .livequery() with on()jQuery:用 on() 替换 .livequery()
【发布时间】:2014-08-20 16:32:31
【问题描述】:

我有以下 jQuery/LiveQuery 代码。

它等到“highlight_this”类出现在页面某处,然后突出显示表格行以引起对刚刚更改的数据行的注意。

因此用户选择编辑一行数据,我们通过 ajax 更新 db,并将更改后的行写回页面,并将 .highlight_this 应用于 <tr>

我使用的是 jQuery 1.11.1,因为我仍然需要支持 IE7。以下在 Firefox 中运行良好,但在 IE7/8/9 中,直到在页面上单击鼠标才会触发,所以我猜我需要停止使用 LiveQuery 并切换到 .on()。

// waits for the tr.highlight_this to appear, highlights th/td within, then returns to previous colour
//---------------------------------------------
$('.highlight_this', 'table').livequery(
    function() {
        var color = $('td', $(this)).css('background-color');
        $('th, td', $(this)).animate({ backgroundColor: '#ffffcc' }, 0 ).delay(1000).animate({ backgroundColor: color }, 5000, function(){ $(this).removeClass('highlight_this'); $(this).removeAttr('style'); })
});

如何使用 .on() 复制此行为?我似乎无法弄清楚如何以这种方式使用 .on()。

亲切的问候, 布拉德利

【问题讨论】:

  • 您可能正在寻找 DOMNodeInsertedIntoDocument 事件,请参阅MDN
  • jquery on 在 1.11.1 版本中可用吗?

标签: jquery livequery


【解决方案1】:

试试这个 -:

 $(document).on("visible", "[class*='.highlight_this, table']", function() {
     var color = $('td', $(this)).css('background-color');
     $('th, td', $(this)).animate({
         backgroundColor: '#ffffcc'
     }, 0).delay(1000).animate({
         backgroundColor: color
     }, 5000, function() {
         $(this).removeClass('highlight_this');
         $(this).removeAttr('style');
     })
 });

来源-: https://stackoverflow.com/a/11701445/6590082

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-09-06
    • 1970-01-01
    • 2011-09-26
    • 2014-04-04
    • 2013-06-22
    • 1970-01-01
    • 2011-03-16
    • 2010-12-25
    相关资源
    最近更新 更多