我相信可以將一個DOM對象數組傳遞給jQuery的選擇器,以便您可以同時處理多個對象。我試着這樣做如下,但不能讓它出於某種原因...將數組傳遞給jQuery Selector
$(Sel).animate({
backgroundColor: "#FF0000"
}, 250, 'linear', function() {
$(this).animate({
backgroundColor: "#FFFFFF"
}, 250, 'linear');
});
它實際上是有可能做到這一點還是我找錯了樹?
我把this jsFiddle放在一起測試一下。其目的是爲預訂系統選擇半小時的插槽,因此我需要在下一行操作「this」和下面的單元格。
任何意見不勝感激。從小提琴
代碼:
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();
[根據文檔(http://api.jquery.com/jQuery/# jQuery1),它有可能:*「'jQuery(elementArray)':一個包含一組DOM元素的數組來包裝在一個jQuery對象中。」*什麼是'Sel'? *編輯:* nvm,沒有看小提琴。 – 2012-08-13 15:41:15