繁体   English   中英

在剧院内插入tr和td

[英]Insert a tr and td inside a thead

我目前有一个cshtml / javascript / jQuery webapp,我想在<table>的现有<thead>内的<tr>内插入<td> <table> 我不知道如何在现有的<thead>插入<tr> <thead> 我知道如何创建并填充它,但是如何插入新行?

我要插入:

<tr class="ligne" style="height: 0px; background-color: white;">
    <td style="border-bottom: black 1px solid; padding-bottom: 0px; height: 1px; padding-top: 0px;" colSpan="6"/>
</tr>

我想将其插入下面的所选行下面:

在此处输入图片说明

我该如何实现?

如果要向容器中添加元素,请在该容器的子级之后使用jQuery方法append()

但是,如果您希望此元素成为容器的第一个子元素,请使用jQuery方法prepend()

在你的情况下,我会做:

$("#GrilleBilan .t-grid-header").prepend("<tr><td> ... </td></tr>")

尝试这个 :

<thead id='insert_tr'>
</thead>

这是您的thead,您可以将tr和td都插入到thead中,如下所示:

var appendtr = "";
appendtr += "<tr><th></th></tr>";//And last append this variable inside thead:
 $("#insert_tr").append(appendtr);

您也可以在for循环的帮助下插入多个tr和td和th

for(var tr = 1; tr <= 5; tr++)
(
 appendtr += "<tr><th></th></tr>";
  $("#insert_tr").append(appendtr);
)

如果您要在广告使用以下代码后插入<tr><td></td></tr>

$('#GrilleBilan .t-grid-header').after('Your element to insert')

我正在使用表ID(#GrilleBilan),因为如果您有多个表,它不会将其替换为其他表。

对不起,我错过了

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM