欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

asp.net使用jQuery获取RadioButtonList成员选中内容和值示例

程序员文章站 2024-02-25 18:47:15
复制代码 代码如下:<%@ page language="c#" autoeventwireup="true" codebehind="default.aspx.cs...

复制代码 代码如下:

<%@ page language="c#" autoeventwireup="true" codebehind="default.aspx.cs" inherits="web.default" %>

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="jquery-1.8.2.min.js" type="text/javascript"></script>
    <link href="base.css" rel="stylesheet" type="text/css" />
    <style type="text/css">

    </style>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#<%=rblhobbies.clientid%> input[type=radio]").bind("change", function () {
                if ($(this).val() != "") {
                     $("#message").text("text:" + $(this).next().text() + "  value:"+$(this).val());
                }

            });
        });

    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div style="margin: 100px auto; width: 400px; height: 200px;">
        <fieldset style="width: 400px; height: 150px">
            <p>
                请选择爱好</p>
            <asp:radiobuttonlist id="rblhobbies"  runat="server" >

                <asp:listitem value="1">音乐</asp:listitem>
                <asp:listitem value="2">篮球</asp:listitem>
                <asp:listitem value="3">美剧</asp:listitem>
                <asp:listitem value="4">电影</asp:listitem>

            </asp:radiobuttonlist  >
        </fieldset>
        <br />
        <div id="message" style="color:blue;"></div>
    </div>
    </form>
</body>
</html>