在th中插入th [英] Insert th in thead
问题描述
我想在 thead $ c>的
tr
内插入 th
$ c>表格的元素。我正在使用在 table.tHead
下创建的行对象的 insertCell
方法,它实际上将 TD
。有没有没有使用任何JS库的JavaScript解决方案?
更新
目前我使用与 Minko Gechev 和 gaurav 。我想知道是否有任何干净的解决方案,如使用 insertCell
?
你可以用vanilla JavaScript来做到这一点。试试这个:
HTML
< table id =table>
< thead>
< tr>
th first< / th>
< / tr>
< thead>
< / table>
JavaScript
var tr = document.getElementById('table')。tHead.children [0],
th = document.createElement('th');
th.innerHTML =Second;
tr.appendChild(th);
下面是一个例子 http://codepen.io/anon/pen/Bgwuf
I want to insert a th
tag inside tr
of thead
element of a table. I am using insertCell
method of row object created under table.tHead
, which is actually inserting td
. Is there any JavaScript solution without using any JS library?
Update
Currently I am using something same as solution provided by Minko Gechev and gaurav. I want to know if there is any clean solution like using insertCell
?
You can do it with vanilla JavaScript. Try this:
HTML
<table id="table">
<thead>
<tr>
<th>First</th>
</tr>
<thead>
</table>
JavaScript
var tr = document.getElementById('table').tHead.children[0],
th = document.createElement('th');
th.innerHTML = "Second";
tr.appendChild(th);
Here is an example http://codepen.io/anon/pen/Bgwuf
这篇关于在th中插入th的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!