我有以下 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() 。
亲切的问候,布拉德利