【问题标题】:IE7 with rowspan when dynamically collapsing multiple rows (extra space at bottom)动态折叠多行时带有行跨度的 IE7(底部有额外空间)
【发布时间】:2011-07-09 04:14:22
【问题描述】:

我正在尝试使用 Javascript 动态隐藏/取消隐藏多个表格行来模拟折叠/展开。以下是相关代码sn-ps:

function selectionFilter(check, filter){
        var elem = document.getElementById('myScrollTable').rows;
        for(i = 0; i < elem.length; i++){
            var type = elem[i].getAttribute('type');
            if(type== filter){
                if(check == true){
                    elem[i].style.display='';
                }else{
                    elem[i].style.display='none';
                }
            }
        }
    }

这里是示例 HTML:

    <input type="checkbox" checked="true" value="t1" onclick="selectionFilter(this.checked, this.value);">some type 1</input >
<input type="checkbox" value="t2" onclick="selectionFilter(this.checked, this.value);">some type 2</input ><br><br>
<table cellspacing="1" cellpadding="2" class="" id="myScrollTable">
    <thead>
        <tr>
            <th>Data1</th>
            <th>Data2</th>
        </tr>
    </thead>

    <tbody>
        <tr type="t1">
            <td rowspan="50"><a href="something1">something1</a></td><td><a href="something2">something2</a></td>
        </tr>
        <tr type="t1">
            <td><a href="something2">something2</a></td>
        </tr>
            .
            .
        <tr type="t2" style="display:none;">
            <td rowspan="50"><a href="something1">something1</a></td><td><a href="something2">something2</a></td>
        </tr>
        <tr type="t2" style="display:none;">
            <td><a href="something2">something2</a></td>
        </tr>
            .
            .
    </tbody>
</table>

在 Firefox 中一切正常。但是在 IE 中,第一次隐藏任何行后,当它被取消隐藏时,它会在底部附加一些额外的空间。不使用行跨度时不会发生这种情况。我尝试了很多东西,但无法摆脱多余的空间。

如果有人能给我一些提示,我将不胜感激。

【问题讨论】:

  • 可能不相关,但在该 HTML 示例中,您似乎缺少type="t2" 附近的开头&lt;tr&gt; 标记。
  • 感谢您的告知,这是真的。我即时编写了示例,它可能不是真正的工作版本。

标签: html internet-explorer html-table row hide


【解决方案1】:

您是否尝试使用 block 代替空字符串?

你应该尝试使用

elem[i].style.display = 'block';

如果失败了,你应该尝试

elem[i].style.display = 'table-row';

你应该检查 w3schools 文档,它真的很有用 http://www.w3schools.com/css/pr_class_display.asp

告诉我这是否适合你

【讨论】:

  • 感谢您的回复。我尝试了这些选项,但不幸的是我没有运气。除了我对提供的 html 代码做了一些小改动(将 rowspan="50" 从 标记移动到 ,我的错)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-20
  • 1970-01-01
  • 2011-11-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多