[英]Button That When Clicked Will Display Hidden Column in HTML Table
Quick question. 快速提问。 I have a button defined as: 我有一个按钮定义为:
<input type='button' id='button' value='Development View' >
A div tag that encloses the following information: 包含以下信息的div标签:
echo "<div id = 'content' style='display:none'>";
echo "<th>Development Status</th>";
echo "</div>";
Some JavaScript that runs whenever the button is clicked: 每当单击按钮时就会运行一些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';
}
};
My ultimate goal is to toggle the visibility of a column in a dynamic HTML table but I can't even get this simple header tag toggling. 我的最终目标是切换动态HTML表中列的可见性,但是我什至无法切换这个简单的标题标签。 I do not get an error message but the button does nothing it seems. 我没有收到错误消息,但是该按钮似乎没有任何作用。 I am echoing out the HTML because this is a PHP script. 我回显了HTML,因为这是一个PHP脚本。
Wrap your javascript in a window.onload event 将您的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';
}
}
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.