0
只是爲什麼我的風格沒有被應用在下面的jQuery中。它也只是增加了FireFox中的表格jQuery.addClass不添加類
$("#advisorPerformance").append("<table class='mvc'><tr><th>Advisor</th><th>Packs In</th><th>Pack In (£)</th><th>Packs Out</th><th>Pack Out (£)</th><th>PDQs</th><th>PDQ (£)</th></tr>");
$.each(data.AdvisorPerformances, function(i) {
$("#advisorPerfomance").append("<tr>" +
"<td>" + data.AdvisorPerformances[i].Advisor +
"</td>" +
"<td>" + data.AdvisorPerformances[i].PackInCount +
"</td>" +
"<td>" + data.AdvisorPerformances[i].PacksInValue +
"</td>" +
"<td>" + data.AdvisorPerformances[i].PacksOutCount +
"</td>" +
"<td> " + data.AdvisorPerformances[i].PaymentsInCount +
"</td>" +
"<td>" + data.AdvisorPerformances[i].PaymentsInValue +
"</td>" +
"</tr>");
});
$("#advisorPerfomance").append("</table>");
$("#advisorPerfomance").addClass("NOTAPPLIEDSTYLE");
還有更好的方法來添加表嗎?
您是否缺少打開
是的,它沒有包括在內,但它在那裏。 – 2010-04-16 16:36:11
回答
你會想要做這樣的事情用
.appendTo()
,使其更快,更重要的是,工作:)a.append()
不只是追加文本並使其HTML,它的創建DOM元素,所以你的第一條線目前正在創建一個未封閉的<table>
......所以從那時起,你將有不可預知的結果。相反,要麼追加完整的有效元素,要麼像上面那樣構建表格,然後將其添加到DOM。上面的方法創建了一個文檔片段中的DOM之外的表,然後附加它,這是既快又清潔。完成後,將整個表格添加到#advisorPerformance
。來源
2010-04-16 17:10:48
我注意到你的一些代碼使用「advisorPerfomance」,而其他代碼使用「advisorPerformance」。我猜想你正試圖「addClass」的JQuery選擇器會產生一個長度爲零的數組,因此它將該類添加到沒有元素。
總之,請務必確保選擇器返回您認爲您選擇的內容。
來源
2010-04-16 16:39:42
好點。實際的代碼拼寫是否與示例中一樣?見下文。 $ .each(data.AdvisorPerformances,function(i){(「#advisorPerfomance」)。append(「
hmm拼寫錯誤是一個紅色的鯡魚,我改變了我以爲所有的拼寫錯誤,所以沒有看起來很愚蠢,我再次失敗了。:) – 2010-04-16 20:33:49
相關問題