微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何使用纯JavaScript在Table中创建TBody标签?

如何使用纯 JavaScript在Table标签中创建TBody标签? (没有手动篡改HTML代码).有HTMLTableElement.createTHead()和HTMLTableElement.createTFoot()函数,但没有关于TBody元素的函数.要添加到此,一旦创建了一个THead元素,使用HTMLTableElement.insertRow()添加到表中的所有以下行都将添加到THead元素中.

你如何去创建一个TBody元素下面,而不用手工篡改HTML?

解决方法

DOM Level 1 spec

Interface HTMLTableElement

The create and delete methods on the table allow authors to construct
and modify tables. HTML 4.0 specifies
that only one of each of the CAPTION,
THEAD,and TFOOT elements may exist in
a table. Therefore,if one exists,and
the createTHead() or createTFoot()
method is called,the method returns
the existing THead or TFoot element.

所以createTHead和createTFoot是不一定做实际创建的便利方法.

相比之下,表格元素可以具有您喜欢的多少,因此无需特殊方法,而HTMLTableElement.appendChild(document.createElement(‘tbody’))将完成整个作业.

原文地址:https://www.jb51.cc/js/154549.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐