爲.net裏面的RadioButtonList添加選擇事件

爲了讓根據選擇的  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>


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章