我有下面的代碼問題:Javascript和很長的字符串
function showTableData()
{
var tableArray;
var x = 0;
var theHTML;
for (i = 0; i < 7032; i++)
{
if (x = 0)
{
theHTML = '<tr>' +
'<th scope="row" class="spec">' + partNum[i] + '</th>' +
'<td>' + Msrp[i] + '</td>' +
'<td>' + blah[i] + '</td>' +
'<td>' + blahs[i] + '</td>' +
'</tr>' + theHTML;
x++;
}else{
theHTML = '<tr>' +
'<th scope="row" class="specalt">' + partNum[i] + '</th>' +
'<td class="alt">' + Msrp[i] + '</td>' +
'<td class="alt">' + blah[i] + '</td>' +
'<td class="alt">' + blahs[i] + '</td>' +
'</tr>' + theHTML;
x--;
}
}
theHTML = '<table id="mytable" cellspacing="0">' +
'<tr>' +
'<th scope="col" abbr="Configurations" class="nobg">Part Number</th>' +
'<th scope="col" abbr="Dual 1.8">Msrp Price</th>' +
'<th scope="col" abbr="Dual 2">blahs Price</th>' +
'<th scope="col" abbr="Dual 2.5">Low Price</th>' +
'</tr>' + theHTML + '</table>';
$('#example').append(theHTML);
}
</script>
<div id="example">
</div>
的問題之處在於$( '#例子')附加(theHTML);從不執行(或在頁面上顯示)。我認爲它是因爲這個字符串太長了!它在陣列中有超過7000個物品,所以我不知道這是否是其原因或其他東西?
任何幫助將是偉大的!謝謝!
大衛
`如果(X = 0)`(9號線)應該是`如果(x == 0)`不知道這是否只是一個錯字雖然 – Hemlock 2011-01-09 03:52:09
你確定函數調用正確嗎? – 2011-01-09 03:52:32
一些建議。使用`push`構建數組而不是字符串連接。然後在添加html之前使用`array.join('')`。更好的性能。 – Hemlock 2011-01-09 03:55:13