使用Jquery删除并向服务器端控件添加一行到表

时间:2014-03-18 15:21:32

标签: javascript jquery asp.net

我有一行有服务器端控件。根据我需要完全删除行的条件,以便屏幕阅读器无法读取HTML,并在条件更改后重新添加。

这是我正在尝试的代码,但它无法正常工作

我原来的ASPX

    table id="tblmain" width="100%">
        <tr>
            <td valign="top">
                <div id="studysub_animal" runat="server">
                    <h3>
                     Select the vALUE.</h3>
                    <asp:RadioButtonList  ID="rdb_one" runat="server">
                        <asp:ListItem Value="Humans">Humans</asp:ListItem>
                        <asp:ListItem Value="Non-Human primates">Non-Human primates</asp:ListItem>                            
                    </asp:RadioButtonList>
                </div>
            </td>
            </tr>
            <tr id="tr_optional">
            <td>

                    <h3> Select your second value</h3>
                    <asp:RadioButtonList ID="rdb_two" runat="server">
                        <asp:ListItem>Individuals</asp:ListItem>
                        <asp:ListItem>Population</asp:ListItem>
                    </asp:RadioButtonList>

            </td>
        </tr>
    </table>

这是我正在写的jquery

     $('#<%=rdb_one.ClientID%> input:radio').click(function () {

                var currentIdone = 'Humans';
                var currentId = $(this).val();
                var row = $('#tr_optional');
                if (currentId == currentIdone) {
                    if ($('#tr_studypopul').length) {

                    }
                    else {

                        $('#tblstudysub_animal').append(row);
                    }

                }
                else {
                    $('#tr_studypopul').detach();

                }

            });

任何想法。我怎样才能添加和删除行conditioanly。 当页面首次加载时,它会加载它只隐藏或可见的行,具体取决于答案

1 个答案:

答案 0 :(得分:1)

像大卫说的那样,你无法动态添加服务器端控件。但是,由于稍后将根据条件显示,为什么不隐藏它呢?尝试使用javascript document.getElementsById()。style.display ='none'。当你显示它时,将“无”更改为“阻止”。它对我有用。

相关问题