动态折叠多行时具有行跨度的 IE7(底部有额外空间)

发布于 2024-10-20 12:54:46 字数 2051 浏览 1 评论 0原文

我正在尝试使用 Javascript 动态隐藏/取消隐藏多个表行来模拟折叠/展开。这里是相关的代码片段:

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 中,第一次隐藏任何行后,当它取消隐藏时,它的底部会附加一些额外的空间。当不使用 rowspan 时,不会发生这种情况。我尝试了很多方法,但无法摆脱多余的空间。

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

I'm trying to dynamically hide/unhide multiple table rows using Javascript to mimic collapse/expand. here are relevant code snippets:

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';
                }
            }
        }
    }

and here is the sample 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>

In Firefox everything is fine. However in IE, after the first time any row is hidden, when it is unhidden it has some extra space appending at the bottom. This does not happen when rowspan is not used. I tried many things but couldn't get rid of the extra space.

I would truly appreciate if anyone could give me some hint.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月寒剑心 2024-10-27 12:54:46

您是否尝试使用 block 而不是空字符串?

你应该尝试使用

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

,如果失败你应该尝试

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

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

告诉我这是否有效为你

Did you try using block instead of an empty string?

you should try using

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

and if this fails you should try

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

and allways you should check the w3schools documentation, its really usefull
http://www.w3schools.com/css/pr_class_display.asp

tellme if this works for you

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文