gpt4 book ai didi

javascript - 如何使用 Jquery 将 th 动态添加到现有的 th

转载 作者:行者123 更新时间:2023-11-30 10:12:11 28 4
gpt4 key购买 nike

我如何使用 Jquery 动态地为 th 添加值。我希望在 Heading7 之后将值附加到 Heading8 和 Heading9

<thead>
<tr>
<th>Heading1</th>
<th>Heading2</th>
<th>Heading3</th>
<th>Heading4</th>
<th>Heading5</th>
<th>Heading6</th>
<th>Heading7</th>
</tr>
</thead>

最佳答案

使用 jQuery append:

//adds new <th> Heading8 after Heading7
$('thead tr').append( $('<th />', {text : 'Heading8'}) )

//adds new <th> Heading9 after Heading8
$('thead tr').append( $('<th />', {text : 'Heading9'}) )

编辑

附加到特定表:

<thead>
<tr id="selectMe">
<th>Heading1</th>
<th>Heading2</th>
</tr>
</thead>

然后使用:

$('#selectMe').append( $('<th />', {text : 'Heading3'}) )

关于javascript - 如何使用 Jquery 将 th 动态添加到现有的 th,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25895922/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com