gpt4 book ai didi

javascript - 单击时将在 HTML 表中显示隐藏列的按钮

转载 作者:太空宇宙 更新时间:2023-11-04 10:41:31 27 4
gpt4 key购买 nike

快速提问。我有一个按钮定义为:

<input type='button' id='button' value='Development View' >

包含以下信息的 div 标签:

echo "<div id = 'content' style='display:none'>";
echo "<th>Development Status</th>";
echo "</div>";

点击按钮时运行的一些 JavaScript:

var button = document.getElementById('button'); // Assumes element with id='button'

button.onclick = function() {
var div = document.getElementById('content');
if (div.style.display !== 'none') {
div.style.display = 'none';
}
else {
div.style.display = 'block';
}
};

我的最终目标是在动态 HTML 表格中切换列的可见性,但我什至无法切换这个简单的标题标签。我没有收到错误消息,但按钮似乎什么也没做。我回显了 HTML,因为这是一个 PHP 脚本。

最佳答案

将您的 javascript 包装在 window.onload 事件中

window.onload = function () {

var button = document.getElementById('button'); // Assumes element with id='button'

button.onclick = function() {
var div = document.getElementById('content');
if (div.style.display !== 'none') {
div.style.display = 'none';
}
else {
div.style.display = 'block';
}
}
};

关于javascript - 单击时将在 HTML 表中显示隐藏列的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35756143/

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