为.net里面的RadioButtonList添加选择事件

来源:互联网 发布:射手男 知乎 编辑:程序博客网 时间:2024/05/16 02:59

为了让根据选择的  RadioButtonList值不同,隐藏或显示一些页面上的信息

(比如,添加文章是选择次文章是否为转载,如果是转载的话,需要添加转载信息,如果不是,就隐藏这些信息)。

相关代码如下:

1.页面表格内容。

            <tr>                <td>                    来源:                 </td>                <td>                    <asp:RadioButtonList ID="rblType" runat="server"                         RepeatDirection="Horizontal">                        <asp:ListItem Value="0" Selected="True">原创</asp:ListItem>                        <asp:ListItem Value="1">转载</asp:ListItem>                    </asp:RadioButtonList>                </td>            </tr>            <tr class="fromInfo">                <td>                    作者:</td>                <td>                    <asp:TextBox ID="txtAuthor" runat="server"></asp:TextBox>                </td>            </tr>            <tr class="fromInfo">                <td>                    转自:                </td>                <td>                    <asp:TextBox ID="txtUrl" runat="server" Width="380px"                         MaxLength="500"></asp:TextBox>                </td>            </tr>

2.js相关代码,此处使用了Jqery

<script type="text/javascript">        $(document).ready(function () {            check();            $(":radio").click(function () {                check();            });        function check() {            if ('1' == $(":checked").val()) {                $(".fromInfo").show();            } else {                $(".fromInfo").hide();            }        }        });</script>