我有一个C#.NET页面,我想在按下按钮时使行折叠。我找到了很多像这样的教程( http://codingforums.com/archive/ index.php?t-90375.html ),尝试实施他们的解决方案,但当我点击我的按钮时,他们都没有为我做任何事情。为了确保我不会发疯,我做了一个小测试页面,看看这个想法是否有效。出于某种原因,事实并非如此。浏览器是IE6。我正在运行Visual Studio 2005.有没有人知道为什么这不起作用?渲染页面显示了一个按钮和一行文字,正如我所期望的那样;单击按钮时,文本行不会消失。我知道我可以使用div,但请记住这只是概念的证明;在我的实际应用程序中,表格行必须崩溃。

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Test.aspx.cs" Inherits="Project.Web.Auth.Test" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Shop Financials</title>
    <link href="../StyleSheets/ClaimsV2.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">     


        function btnClick(control)
        {   
            try
            {
                var id_table = document.getElementById(control).style;

                if(id_table.display == "block") 
                {
                   id_table.display = "none";
                }
                else 
                {
                    id_table.display = "block";
                }
            }
            catch(e)
            {
                alert(e);
            }   
       }

       function toDepositPrinterFriendly()
       {

       }

  </script>
</head>
<body>
    <form id="form1" runat="server">

    <table>
    <tr>
    <td><asp:Button runat="server" OnClientClick="javascript:btnClick('HeaderRow')"/></td>

    </tr>
    <tr id="HeaderRow" runat="server">
    <td>TEST2</td>

    </tr>    


    </table>

    </form>
</body>
</html>
有帮助吗?

解决方案

1)显示器(可能)最初不是“阻止”。尝试:

if(id_table.display == 'none') 
{
  id_table.display = '';
}
else 
{
  id_table.display = 'none';
}

2)由于命名容器。检查您的HTML源

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top