我有這段代碼,我需要對前2個項目做些事情,然後再做其他事情,但是怎麼做? 我從<tr data-name='test' data-price='2' data-one='blabla' ...
對於每個功能。先做2件事,然後做其他事情?
data = $(this).data();
html_option = "<table id='Unit_Options_Table'>";
// Do some thing with the first 2
$.each(data, function(option, cost) { // Then do something with the rest
html_option += "<tr>" +
"<td class='Unit_Options_Name_td'>" + option + "</td>" +
"<td class='Unit_Options_Cost_td'>" + cost + "</td>" +
"</tr>";
});
html_option += "</table>";
'each',正如其名稱中明確規定,不帶*每個*元素的東西。所以你顯然不能在這裏使用它。 –
你在循環一個數組還是一個對象? – bfavaretto
@bfavaretto數據是jQuery節點對象的數組 - 它在其代碼的第一行中定義。 –