仅使用javascript将列数据追加到html表中

时间:2014-04-09 05:34:37

标签: javascript html

我有一组数组

Case =[case1, case2,case3]
Condition = [condition1,condition2,condition3]
Observation = [obs1,obs2,obs3]

如何在具有以下格式的html表格中显示?案例条件和观察是不改变的标题。基本上列的数量不会改变只有行的变化。我怎么能用javascript做到这一点?

我是javascript的新手,我在迭代方面遇到了困难。

+----------------------------------
| Case  | Condition  | Observation| 
+---------------------------------+
| case1 | condition1 | obs1       |
+---------------------------------+
| case2 | condition2 | obs2       | 
+---------------------------------+
| case3 | condition3 | obs3       | 
+---------------------------------+

1 个答案:

答案 0 :(得分:1)

尝试使用 JS

Case =["case1", "case2","case3"];
Condition = ["condition1","condition2","condition3"];
Observation = ["obs1","obs2","obs3"];

for(i=0;i<Case.length;i++)
{
    document.getElementById(tableid).innerHTML+="<tr><td>"+Case[i]+"</td><td>"+Condition[i]+"</td><td>"+Observation[i]+"</td></tr>"
}

Demo Fiddle