【发布时间】: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 版本中可用吗?