我想將數組發送到eq
函數作爲參數。這樣的:jquery數組轉換爲eq函數
$(this).find('tr').not(':eq(array)').each(function(){
});
我這樣做是使用一個循環,並eval
功能,但它並不容易編輯。這是我的代碼。
$.fn.grilestir = function(options){
var nots = '';
for(var i=0;i<options.row_numbers.length;i++){
nots += "not(':eq("+options.row_numbers[i]+")').";
}
eval("$(this).find('tr')."+nots+"each(function(){\
var tr = $(this); var orj;\
if(options.mod == 'passive-rows'){\
$(this).mouseover(function(){\
orj = tr.css('backgroundColor');\
tr.css('backgroundColor', '#777777');\
});\
$(this).mouseout(function(){\
tr.css('backgroundColor', orj); \
});\
}\
});");
}
有沒有辦法做到這一點?
如果它的jQuery對象的數組,你可以做'。不是(陣列)'。你的數組包含什麼數據?另外,使用'eval()'不是一個好主意。 – Bojangles 2012-02-14 14:06:17
ewww eval是邪惡的 – mcgrailm 2012-02-14 14:08:29