C# .NET / javascript:可折叠表行 - 这是错误的吗?
我有一个 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>
I have a C# .NET page where I want to make rows collapse when a button is pressed. I found many tutorials like this one (http://codingforums.com/archive/index.php?t-90375.html), tried to implement their solutions, but none of them do anything for me when I click my button. To make sure I wasn't going crazy, I made a small test page just to see if the idea works. For some reason, it isn't. The browser is IE6. I'm running Visual Studio 2005. Does anyone have any idea why this isn't working? The rendered page shows a button and a line of text as I would expect; the line of text does not disappear when I click the button. I know I could use divs, but remember this is just a proof of concept; in my real application it is table rows that must collapse.
<%@ 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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
1) 显示器最初(可能)不是“阻塞”的。 尝试:
2)控件的id不会是你想象的那样,感谢命名容器。 检查您的 HTML 源代码
1) The display is (probably) not 'block' initially. Try:
2) The id of the control will not be what you think it is, thanks to Naming Containers. Check your HTML Source