我有以下jQuery/LiveQuery代码。
它等待一个"highlight_this“类出现在页面上的某个地方,然后突出显示一个表行,以便引起对刚刚更改的数据行的注意。
因此,用户选择编辑一行数据,我们通过ajax更新数据库,更改后的行将被写回页面,并对<tr>应用.highlight_this。
我使用的是jQuery 1.11.1,因为我仍然需要支持IE7。下面的代码在火狐中运行良好,但在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()。
致以亲切的问候,布拉德利
发布于 2016-09-21 21:31:31
试试这个-:
$(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/questions/25409959
复制相似问题