首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >jQuery:将.livequery()替换为on()

jQuery:将.livequery()替换为on()
EN

Stack Overflow用户
提问于 2014-08-21 00:32:31
回答 1查看 268关注 0票数 0

我有以下jQuery/LiveQuery代码。

它等待一个"highlight_this“类出现在页面上的某个地方,然后突出显示一个表行,以便引起对刚刚更改的数据行的注意。

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

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

代码语言:javascript
复制
// 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()。

致以亲切的问候,布拉德利

EN

回答 1

Stack Overflow用户

发布于 2016-09-21 21:31:31

试试这个-:

代码语言:javascript
复制
 $(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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25409959

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档