2

我有一个 asp.net gridview,我在其中使用选定复选框上的“onclick”隐藏和显示列。单击时,隐藏的列在 IE 中显示良好,但在 Chrome、Firefox 中它们重叠。我一定遗漏了一些东西,就好像它们被添加到同一列中一样。因为我是新手,所以我可以发布屏幕截图。

非常感谢任何帮助。

function showColumn(r,grid) {

rows = document.getElementById("GridView1").rows;
drop = document.getElementById(grid);
if (drop.checked == true) {

    for (i = 0; i < rows.length; i++) {
        rows[i].cells[r].style.display = "block";

        }
    }

else if (drop.checked == false) {
    for (i = 0; i < rows.length; i++) {
        rows[i].cells[r].style.display = "none";

        }
    }
}

<p>
    <asp:CheckBox ID="CheckBox1" runat="server" onclick="showColumn(2,'CheckBox1')" 
        Text="Show Option Name" />
</p>
<p>
    <asp:CheckBox ID="CheckBox2" runat="server" onclick="showColumn(1,'CheckBox2')" 
        Text="Show ID" />
</p>
4

2 回答 2

1

而不是使用:

rows[i].cells[r].style.display = "block";

... 要显示表格单元格,请尝试将 display 属性设置为空字符串,以便它返回默认值:

rows[i].cells[r].style.display = "";
于 2012-05-13T00:28:16.037 回答
0

尝试使用visibility:hidden(and visibility:visible) 而不是displaycss 属性。与display:none元素不同的visibilty:hidden是,即使不可见,元素仍处于流中,因此它们不会与其他元素重叠。

于 2012-05-13T00:22:09.477 回答