在th中插入th [英] Insert th in thead

查看:289
本文介绍了在th中插入th的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 thead 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屋!

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