我认为你需要做的事情比你必须在当前的拨弄什么简单得多。有很多事情要做,而且你只需制作HTML就不需要做太多工作。我修改了您的jsfiddle,您可以看到我动态地构建HTML。
var company, link, html = "<tr>", cols = 4, currentCol = 1;
for (company in brand) // Loop through each item in the array
{
if (currentCol > cols) { // Make sure we only have 4 columns
currentCol = 1; // Reset the current column if we go over that
html += "</tr><tr>"; // Stop the previous row and start a new one
}
html += "<td>" + company + "</td>"; // Add the current item to the table
currentCol++; // Increment the column count for the next loop
}
html += "</tr>";
document.getElementById('table').innerHTML = html; // Append the html with our dynamically created html
现在基本完成后,你应该能够在任何丢失部分我公司提供的基本模板添加(如添加锚链接等)。有时候使用document
API可能会让你感到有点畏缩和过度杀伤,因为你可以自己编写HTML。
你有没有考虑过使用模板库? – Blowsie
另外'colspan ='不是表的有效属性。 http://www.w3schools.com/tags/tag_table.asp – Blowsie
不幸的是,我只限于纯粹的JS – Volterony