0

我有一些最初不可见的 ASP.NET 表行。单击时,我正在运行一个 Javascript 函数,该函数正在更改显示或隐藏它的表格行的样式。

要显示它:

document.getElementById(id).style.display = ""; 

隐藏它:

document.getElementById(id).style.display = "none";

这有效。

问题是,当且仅当行可见时,我才需要对行的内容进行一些过滤。

在样式后面的代码中,保持设计的状态并且不采用当前状态。

如果元素可见与否,获取信息的最佳方法是什么?

4

2 回答 2

0

当您运行该 JavaScript 时,您需要更改服务器控件中某些内容的值(这将使用新值回发到服务器)。如果您还没有任何东西,您可以使用像 HiddenField 控件这样简单的东西。

因此,您可以将其添加到您的标记中:

<asp:HiddenField ID="isRowShowing" Value="True" runat="server" />

然后在您的 JavaScript 函数中执行此操作:

//To show
document.getElementById(id).style.display = "";
document.getElementById('<%= isRowShowing.ClientID %>').value = "True";

//To Hide
document.getElementById(id).style.display = "none";
document.getElementById('<%= isRowShowing.ClientID %>').value = "False";

然后你可以在后面的代码中检查它:

if(isRowShowing.Value == "True")
{
    // Do stuff
}
else
{
    // Do other stuff.  Or don't do stuff.  Whatevs.
}
于 2013-03-25T14:41:05.737 回答
0

To show it:

document.getElementById(id).style.display="inline";

To hide it:

document.getElementById(id).style.display="none";

To check it:

if(document.getElementById(id).style.display=="inline") {
    //Do your stuff
    }

Or am I missing something?

于 2013-03-25T14:52:33.717 回答