0

我想在选项卡为 2 时隐藏按钮。总是出错。

<script type="text/javascript">

function clientActiveTabChanged(sender, args) {
if ((sender.get_activeTabIndex()) == '2')
{
    alert(sender.get_activeTabIndex());
    var messageElement = document.getElementById('<%= divMessage.clientID%>').value;
    messageElement.style.display = 'block';
}
}
</script>

<body>
<form id="form1" runat="server">
 <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" 
    EnableScriptGlobalization="True"></asp:ToolkitScriptManager>

<asp:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="0"  
            Width="100%" BorderStyle="None" OnClientActiveTabChanged="clientActiveTabChanged"> 

     <asp:TabPanel runat="server"  ID="TabPanel1"> 
      <HeaderTemplate>Test1</HeaderTemplate>
      <ContentTemplate></ContentTemplate>
    </asp:TabPanel>

  <asp:TabPanel runat="server"  ID="TabPanel2"> 
      <HeaderTemplate>Test2</HeaderTemplate>
      <ContentTemplate></ContentTemplate>
    </asp:TabPanel>

  <asp:TabPanel runat="server"  ID="TabPanel3"> 
      <HeaderTemplate>Test3</HeaderTemplate>
      <ContentTemplate></ContentTemplate>
    </asp:TabPanel>

 </asp:TabContainer>
 <div runat="server" id="divMessage" style="display: none;">
 <asp:Button ID="Button1" runat="server" Text="Button" />
</div> 


</form>

</body>
</html>
4

1 回答 1

0

您在按钮元素上使用 .value 。这将返回按钮的文本,它是一个字符串并且没有样式。以下应该工作。另外,您提到要隐藏它,但您将显示设置为阻止。应该没有。

var messageElement = document.getElementById('<%= divMessage.clientID%>');
messageElement.style.display = 'block';
于 2013-11-05T11:37:54.357 回答