相关疑难解决方法(0)

使用Javascript填充HTML表

我想使用JavaScript填充预定义的html表:

<table>
    <tr>
        <th scope="col">ID</th>
        <th scope="col">Name</th>
    </tr>
    <div id='data'/>
</table>
Run Code Online (Sandbox Code Playgroud)

运用

document.getElementById('data').innerHTML = ....
Run Code Online (Sandbox Code Playgroud)

但由于<div>不允许在<table>上面的代码内部不起作用.实现这一目标的正确方法是什么?

javascript html-table

15
推荐指数
1
解决办法
6万
查看次数

Javascript获取表行TR的单元格

我想用javascript操纵表格单元格,到目前为止我设法进入tr-s,使用:

var as = document.getElementById('answers['+id+']');
var trs = as.getElementsByTagName("tr");
for (var i in trs)
{ ... }
Run Code Online (Sandbox Code Playgroud)

更新:就像桌子一样.

在for循环中,我想要使用相同的登录行,我尝试过:

var tds = trs[i].getElementByTagName("td");
Run Code Online (Sandbox Code Playgroud)

问题是在调试时出现以下错误:

Uncaught TypeError: Object #<HTMLTableRowElement> has no method 'getElementByTagName' .
Run Code Online (Sandbox Code Playgroud)

我怎么能进入tr-s的td-s?

html javascript dom

2
推荐指数
1
解决办法
5万
查看次数

Firefox 浏览器无法识别 table.cells 吗?

我有以下 JavaScript 代码。


var myCellCollection = document.getElementById('myTbl').cells;
Run Code Online (Sandbox Code Playgroud)

这在 IE 中运行良好,它返回一组表格单元格。但同一行在 Firefox 中返回“未定义”。我正在使用 IE 9 和 Firefox 12。

javascript firefox cells

2
推荐指数
1
解决办法
3102
查看次数

循环遍历HTML表格中的元素

我正在学习Javascript,在学校作业中我们必须使用循环计数在2014年制作了多少游戏.

它在控制台中没有返回任何内容,我哪里出错了?

var allGames = document.getElementsByTagName('td');
var array = Array.prototype.slice.call(allGames, 0)
var games14 = 0;
for (var i = 0; i < array.length; ++i) {
  if (array[i] == 2014) {
    games14++;
    console.log(games14)
  }
}
Run Code Online (Sandbox Code Playgroud)
<table id="games">
  <thead>
    <tr>
      <th>Titel</th>
      <th>Genre</th>
      <th>Årstal</th>
    </tr>
  </thead>
  <tbody id="games_tbody">
    <tr class="horror">
      <td class="title">Outlast</td>
      <td>Horror</td>
      <td>2013</td>
    </tr>
    <tr class="rpg">
      <td class="title">Dragon Age: Inquisition</td>
      <td>Role-playing Game</td>
      <td>2014</td>
    </tr>
    <tr class="rpg">
      <td class="title">Skyrim</td>
      <td>Role-playing Game</td>
      <td>2011</td>
    </tr>
    <tr class="horror">
      <td class="title">Amnesia: The Dark Descent</td>
      <td>Horror</td>
      <td>2010</td>
    </tr> …
Run Code Online (Sandbox Code Playgroud)

html javascript arrays dom loops

1
推荐指数
1
解决办法
3963
查看次数

标签 统计

javascript ×4

dom ×2

html ×2

arrays ×1

cells ×1

firefox ×1

html-table ×1

loops ×1