是否可以使用 TableRow.insertCell() 创建 TH? [英] Is it possible to create a TH with TableRow.insertCell()?

查看:41
本文介绍了是否可以使用 TableRow.insertCell() 创建 TH?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码向表中动态添加新行:

I'm adding new rows to a table dynamically, with this code:

tbody = document.getElementById('tbody');
tr = tbody.insertRow(-1);
tr.id = 'last';
th = tr.insertCell(0);
td = tr.insertCell(1);

但我实际得到的是两个 td 单元格.我想要一个 th,如你所见.

But what I actually got are two td cells. I want a th, as you can see.

它表示 tagName 属性不可更改.

It says the tagName property isn't changeable.

我该怎么做?

我是否需要使用像 createElementappendChild 这样的普通"方法?

Will I need to use 'normal' methods like createElement and appendChild?

推荐答案

我没有看到任何允许您执行此操作的官方文档.

I don't see any official docs that allow you to do this.

TR/TR.insertCell 的 W3C 文档

createElement/appendChild 会起作用.

这篇关于是否可以使用 TableRow.insertCell() 创建 TH?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆