zoukankan      html  css  js  c++  java
  • ASP.NET jQuery 随笔 显示CheckBoxList成员选中的内容

    通过jQuery来获取CheckBoxList成员内容。

     <%@ 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 () {
                $("#<%=cblHobbies.ClientID%>").click(function () {
                    var msg = "";
                    $('#<%=cblHobbies.ClientID%> input[type="checkbox"]:checked').each(function () {
                       msg = msg + $(this).val() + ":" + $(this).next().text() + " "; // 这里的next()表示<label>
                    });
                    $("#message").text(msg);
                });
            });
           
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div style="margin: 100px auto;  400px; height: 200px;">
            <fieldset style=" 400px; height: 150px">
                <p>
                    请选择爱好</p>
                <asp:CheckBoxList ID="cblHobbies"  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:CheckBoxList>
            </fieldset>
            <br />
            <div id="message" style="color:Red;"></div>
        </div>
        </form>
    </body>
    </html>

    QQ截图20131212133606

  • 相关阅读:
    Java-Class-C:com.alibaba.fastjosn.JSON.java
    兆芯笔试题(2015)找反复数最多的字母的数量以及位置
    获得文件属性的函数调用实例
    错了:用流量能够放肆,有wifi则要节制
    为什么会找不到D层文件?
    Cocos2d-x3.0游戏实例之《别救我》第六篇——从代码中获取UI控件
    Add Binary
    【iOS开发之Objective-C】书签管理器项目
    UVa 11732 strcmp() Anyone?
    【打CF,学算法——二星级】Codeforces Round #313 (Div. 2) B. Gerald is into Art(水题)
  • 原文地址:https://www.cnblogs.com/jlcoder/p/3470957.html
Copyright © 2011-2022 走看看