如何使用javascript在现有选项卡中添加thead和tbody标记
嗨,我的标签是由应用程序生成的,我不能在html代码中添加thead和tbody标签。 所以我想用javascript添加标签 实际上,我的代码是:如何使用javascript在现有选项卡中添加thead和tbody标记,javascript,html,tabs,Javascript,Html,Tabs,嗨,我的标签是由应用程序生成的,我不能在html代码中添加thead和tbody标签。 所以我想用javascript添加标签 实际上,我的代码是: 名称 地址 。。。 我想 名称 地址 感谢大家事实上,使用datatables代码 我已经找到去的路了 var myTable = jQuery("#__bookmark_1"); var thead = myTable.find("thead"); var thRows = myTable.
名称
地址
。。。
我想
名称
地址
感谢大家事实上,使用datatables代码 我已经找到去的路了
var myTable = jQuery("#__bookmark_1");
var thead = myTable.find("thead");
var thRows = myTable.find("tr:has(th)");
if (thead.length===0){ //if there is no thead element, add one.
thead = jQuery("<thead></thead>").appendTo(myTable);
}
var copy = thRows.clone(true).appendTo("thead");
thRows.remove();
var myTable=jQuery(“书签1”);
var thead=myTable.find(“thead”);
var thRows=myTable.find(“tr:has(th)”;
如果(thead.length==0){//如果没有thead元素,则添加一个。
thead=jQuery(“”).appendTo(myTable);
}
var copy=thRows.clone(true).appendTo(“thead”);
抛出。移除();
为什么要这样做?如果仅用于样式设置,则使用tr:first child
伪类选择器仅设置第一行(标题)的样式就足够了。
<table id="__bookmark_1">
<thead>
<tr>
<th>name</th>
<th>adress</th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
<tbody>
</table>
var myTable = jQuery("#__bookmark_1");
var thead = myTable.find("thead");
var thRows = myTable.find("tr:has(th)");
if (thead.length===0){ //if there is no thead element, add one.
thead = jQuery("<thead></thead>").appendTo(myTable);
}
var copy = thRows.clone(true).appendTo("thead");
thRows.remove();