gpt4 book ai didi

javascript - 在javascript中隐藏列

转载 作者:行者123 更新时间:2023-11-30 14:43:54 25 4
gpt4 key购买 nike

我想隐藏表中列的值,表的数据是从数据库绑定(bind)的

这是我的html代码

<table id="datatable-responsive" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">                                                                          
<thead>
<tr>
<th id="th_id_event">Id Event Category</th>
<th>Event Category</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<% objLOV.forEach(function (lov) { %>
<tr onclick="callme(this)">
<td id="td_id_event">
<%= lov.id %>
</td>
<td>
<%= lov.event_category %>
</td>
<td>
<%= lov.description %>
</td>
</tr>
<% }) %>
</tbody>
</table>

<% objLOV.forEach(function (lov) { %>就是从数据库中获取数据

我试过这样,但是只有第一列第一行被隐藏,我想隐藏列id的所有值

window.onload = function () {
document.getElementById("td_id_event").style.display = "none";
document.getElementById("th_id_event").style.display = "none";
};

my table

my table after i tried to disable

谁能帮帮我?谢谢..

最佳答案

您只能有效地拥有一个具有给定 ID 的元素,因此尝试引用具有相同 ID 的多个元素不太可能奏效。您可以为元素使用一个类,即替换

<td id="td_id_event"

<td class="id_event"

然后使用

window.onload = function () {
var ids = document.getElementsByClassName("id_event");
for (var i = 0; i < ids.length; i++) {
ids[i].style.display = "none";
}

关于javascript - 在javascript中隐藏列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49248002/

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