為.net裡面的RadioButtonList新增選擇事件
阿新 • • 發佈:2019-02-06
為了讓根據選擇的 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>