javascript - <tbody> 元素被填充到表格的第一列

标签 javascript html css

我试图根据选中复选框来隐藏/显示表行。

这是http://dbdev2.pharmacy.arizona.edu/wideproblem.html

如何使隐藏行在表格宽度处正确显示?我什至尝试将其设置为该行的 css 属性,但它不起作用。

这是代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <title>The Case of the Squished Row</title>
<style>
table {
    border: 1px solid black;
     width: 600px;
    }
tr {border:1px solid black;}
tr.anote {width:600px;}
th {
    border:1px solid black;
    width:50%;
    }
td {
    border: 1px solid black;
    width: 25%;
    }

</style>

<script type="text/javascript">
    function ShowRow(msg){
        var thecheck = document.getElementById("showcheck");
        var thebox= document.getElementById("showbox");
        var thenote= document.getElementById("shownote");
        if (thecheck.checked){
            thebox.innerHTML=msg;
            thebox.style.color='red';
            thenote.style.display='block';
            }
        else {
            thebox.innerHTML='This is a checkbox';
            thebox.style.color='black';
            thenote.style.display='none';
            }

        }
</script>
</head>
<body>
<h1>The Case of the Squished Row</h1>
<br><br>
<h2> using display:none CSS property</h2>
<table>
<tbody id="topline">
<tr><th id="showbox">This is a checkbox</th>
<td><input type="checkbox" id="showcheck" onclick="ShowRow('Note is DISPLAY:BLOCK')"></td>
<td>this is filler</td></tr>
</tbody>
<tbody id="shownote" style="display:none">
<tr class="anote"><th>This is a note</th><td>Hey! The box is checked!</td><td>this is filler</td></tr>
</tbody>
<tbody id="botline">
<tr><th>Big Filler</th><td>Little filler</td><td>this is filler</td></tr>
</tbody>
</table>
</body>
</html>

最佳答案

显示表行组(<tbody>)时,您必须使用“table-row-group”而不是“block”作为“display”属性的值。

关于javascript - <tbody> 元素被填充到表格的第一列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19712647/

相关文章:

javascript - 如何使用 Cordova 在缩略图中显示缩小尺寸的图像

javascript - CSS 和 Javascript 耦合太紧(CSS 不仅仅是 presentation 而是 UI 和 JS 所使用的),如何改进?

javascript - 使用 Javascript 解析 URL

javascript - 包括来自 CDN 和本地浏览的库

javascript - 使用javascript按月自动更改图片

javascript - JQuery 提前触发

html - IE8 css 下拉问题悬停不工作

javascript - @Font-face onload方法?

html - CSS 强制顶部 z-index 父级溢出 :hidden

Javascript 动态链接问题?