我相信可以将一个 DOM 对象数组传递给 jQuery 的选择器,这样您就可以同时操作多个对象。我已经尝试按如下方式执行此操作,但由于某种原因无法使其正常工作......
$(Sel).animate({
backgroundColor: "#FF0000"
}, 250, 'linear', function() {
$(this).animate({
backgroundColor: "#FFFFFF"
}, 250, 'linear');
});
真的有可能做到这一点,还是我在吠叫错误的树?
我已经把这个 jsFiddle放在一起来测试一下。目的是制作一个预订系统,其中选择半小时的时段,因此我需要操纵“这个”和下一行下面的单元格。
非常感谢任何建议。
小提琴的代码:
function HighlightCells() {
$('table#Calendar tbody tr td:not(".TimeCell")').live('mouseenter', function() {
var Sel = new Array();
Sel[1] = $(this);
// Count number of previous TDs. Resut is base 0
var NumIn = $(this).prevAll('td').length;
// Increment count to compensate for nth-child being base 1
NumIn++;
var NextRow = $(this).closest('tr').next('tr');
Sel[2] = $(NextRow).children("td:nth-child(" + NumIn + ")");
// Animate the cell background colour red to white
$(Sel).animate({
backgroundColor: "#FF0000"
}, 250, 'linear', function() {
$(this).animate({
backgroundColor: "#FFFFFF"
}, 250, 'linear');
});
$('table#Calendar tbody td').live('mouseleave', function() {
$(this).text("");
});
});
}
HighlightCells();