我遇到了以下代码的问题:
问题在于 $('#example').append(theHTML); 从未执行(或显示在页面上)。我认为这是因为字符串太长了!它的数组中有超过7,000个项目,所以我不确定是否是这个原因或其他原因?
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>
问题在于 $('#example').append(theHTML); 从未执行(或显示在页面上)。我认为这是因为字符串太长了!它的数组中有超过7,000个项目,所以我不确定是否是这个原因或其他原因?
任何帮助都将是极好的!谢谢!
大卫
if (x==0)
,不确定这是否只是一个打字错误。 - Hemlockpush
构建数组而不是字符串拼接。然后在附加 HTML 之前使用array.join('')
。性能更好。 - Hemlock