gpt4 book ai didi

javascript - 从 Javascript 函数更改 HTML 表格样式?

转载 作者:行者123 更新时间:2023-12-03 08:30:25 24 4
gpt4 key购买 nike

我有这张表:

<table id="classTable" style="width:40%">
<tr>
<td>WCOB 2053: Business Foundations</td>
<td>MWF 10:45am</td>
</tr>
<tr>
<td>MATH 2043C: Survey of Calculus</td>
<td>MW 12:55pm</td>
</tr>
<tr>
<td>ISYS 2103: Business Information Systems</td>
<td>MW 4:30pm</td>
</tr>
<tr>
<td>ISYS 2263: Principles of Information Systems</td>
<td>TTh 9:30am</td>
</tr>
<tr>
<td>CSCE 3193: Programming Paradigms</td>
<td>TTh 11:00am</td>
</tr>
<tr>
<td>SCMT 2103: Introduction to Supply Chain Management</td>
<td>TTh 6:00pm</td>
</tr>

我想用一个调用函数的按钮来控制该表的可见性,所以我认为我需要使用

style="display:none";

但是我如何在函数中更改它呢?我假设类似

document.getElementById("classTable").style.display = "none";

但我在任何地方都找不到这方面的文档。

最佳答案

你可以在你的按钮上做这样的事情:

<button onclick="myFunction()">Click me</button>


<script>
function myFunction() {
document.getElementById("classTable").style.display = "none";
}
</script>

关于javascript - 从 Javascript 函数更改 HTML 表格样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33357003/

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