【问题标题】:C# .NET / javascript : Collapsable Table Rows - what about this is wrong?C# .NET / javascript : Collapsable Table Rows - 这是怎么回事?
【发布时间】:2008-09-29 18:56:22
【问题描述】:

我有一个 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>

【问题讨论】:

    标签: c# .net collapsable


    【解决方案1】:

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

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

    2) 感谢Naming Containers,控件的 id 不会是你想象的那样。检查您的 HTML 源代码

    【讨论】:

    • 这修复了它。它也在做回发,所以我添加了“return false”;到 javascript。非常感谢!
    • 使用这个概念证明,我得到了“真实”页面的工作:) 你让这个星期一的工作日变得不那么痛苦了......再次感谢你:)
    猜你喜欢
    • 1970-01-01
    • 2011-08-25
    • 1970-01-01
    • 2011-12-17
    • 2011-07-06
    • 1970-01-01
    • 2013-07-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多