[英]Button That When Clicked Will Display Hidden Column in HTML Table
快速提問。 我有一個按鈕定義為:
<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';
}
}
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.