首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在表中显示Javascript链接

在表中显示Javascript链接
EN

Stack Overflow用户
提问于 2014-02-18 19:21:02
回答 1查看 83关注 0票数 0

嗨,我正试着在表格中显示我的链接。链接是从JSON数据源中提取的,我只想在td标记中显示品牌名称。我们的目标是:

代码语言:javascript
复制
<table border="1" colspan="5">

 <tr><td>Nike</td><td>Puma</td><td>etc</td><td>etc</td><td></td><td></td></tr>

</table>

我也需要随着链接列表的增长而增加行数!

这里有一个小提琴:http://jsfiddle.net/volterony/5nW86/

沃特罗尼

EN

回答 1

Stack Overflow用户

发布于 2014-02-18 20:35:38

我认为你需要让事情变得比你现在的小提琴简单得多。有很多事情要做,当你只是做HTML的时候,你不需要做这么多事情。我修改了你的超文本标记语言,你可以看到我是动态构建jsfiddle的。

代码语言:javascript
复制
  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

现在基础工作已经完成,你应该能够添加任何缺少的部分,我提供的基本模板(如添加在锚链接,等等)。有时,当您可以自己编写HTML时,使用HTML可能有点令人望而生畏。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21852178

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档