【问题标题】:Hide Table Row with ASP Control Checkbox使用 ASP 控件复选框隐藏表格行
【发布时间】:2017-10-17 13:25:18
【问题描述】:

在我的网页中,我有一个带有文本框的表格。如果选中了我的 ASP 复选框,我想用文本框隐藏表格行。我该怎么做?

这是我目前所拥有的:

<table>
<tr>
    <td>
        <asp:CheckBox id="chkbxUS" runat="server" onchange="validate();" />
    </td>
</tr>
  <tr>
    <td id="ParentCountryInfo">
      <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    </td>
  </tr>
</table>

<script type="text/javascript">
    function validate() {
        if (document.getElementById('<%=chkbxUS.ClientID%>').checked) {

            document.getElementById("ParentCountryInfo").style.visibility='visible';

        } else {
            document.getElementById("ParentCountryInfo").style.display='block';
        }
    }

</script>

【问题讨论】:

    标签: javascript c# asp.net html-table


    【解决方案1】:

    你能试试这个吗:

    <table>
        <tr>
            <td>
                <asp:CheckBox ID="chkbxUS" runat="server" onchange="validate();" />
            </td>
            <td id="ParentCountryInfo">
                <asp:TextBox ID="TextBox1" runat="server">Disappear me</asp:TextBox>
            </td>
        </tr>
    </table>
    
    <script type="text/javascript">
        function validate() {
            if (document.getElementById('<%=chkbxUS.ClientID%>').checked) {
                document.getElementById("ParentCountryInfo").style.visibility = 'hidden';
            } else {
                document.getElementById("ParentCountryInfo").style.visibility = 'visible';
            }
        }
    </script>
    

    【讨论】:

    • 谢谢。这可行,但是如果从页面加载中选中复选框怎么办?
    • nvm 我想通了Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "validate()", true);
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-08-13
    • 2012-05-19
    • 2010-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多