簡體   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