<div>
  <ul>
  <li style="float:left"><img src="images/medal1.gif" /><br />
      <input id="Checkbox1" type="checkbox" />杰出贡献奖</li>
  <li style="float:left"><img src="images/medal2.gif" /><br /> <input id="Checkbox2" type="checkbox" />优秀学习奖</li>
  <li style="float:left"><img src="images/medal3.gif" /><br /> <input id="Checkbox3" type="checkbox" />优秀版主奖</li>
  <li style="float:left"><img src="images/medal4.gif" /><br /> <input id="Checkbox4" type="checkbox" />荣誉版主将</li>
  <li style="float:left"><img src="images/medal6.gif" /><br /> <input id="Checkbox5" type="checkbox" />学生会员章</li>
  <li style="float:left"><img src="images/medal8.gif" /><br /> <input id="Checkbox6" type="checkbox" />优秀互动师</li>
  </ul>
  <div style="padding-left:5px;">
      <input id="btnMedal" type="button" value="提交" /></div>
</div>
我想用jquery做 当checkbox选中 获取选中到值循环添加到数据库 怎么做?

解决方案 »

  1.   

    $("input[@type=checkbox][@checked]").each(function() { 
    $(this).val()+",";
    });然后ajax提交到后台处理,把获取的值转成数组,然后数组循环添加到数据库
      

  2.   

    JS代码
    // JScript 文件
    function panduan(a)
    {
        var drp=document.getElementById("DropDownList1").value;
        if(drp==0)
        {
        alert('请选择'+a+'类型!');    }
    }function NewsType(b)
    {
        var drp=document.getElementById("txtNewsType").value;
        if(drp.length==0)
        {
        alert('请输入'+b+'类型名称!');    }
    }    function selectall(obj)
        {
        var inputs=$("#tab input[type='checkbox'][id!='cball'] ");
        inputs.attr("checked",obj.checked);    }页面代码
    <%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<IEnumerable<dressWeb.Models.Entities.ProTypetInfo>>" %><!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>
        <title>protypetlist</title>
            <script src="<%=Url.Content("/Scripts/JScript.js")%>" type="text/javascript"></script>
              <script src="<%=Url.Content("/Scripts/jquery-1.4.1.min.js")%>" type="text/javascript"></script>
           <script src="<%=Url.Content("/Scripts/jquery-1.4.1-vsdoc.js")%>" type="text/javascript"></script>
            <link rel="Stylesheet" href="<%=Url.Content("/Content/css/css.css")%>" />
    </head>
    <body>
        <fieldset>
            <legend>商品类型列表</legend>
            <div>
                <%using (Html.BeginForm("protypetlist", "admin", FormMethod.Post))
                  {%>
                <table style="width: 100%; text-align: center" class="tableBorder" id="tab">
                    <tr class="tr">
                        <td style="width: 20%">
                            删除选项
                        </td>
                        <td style="width: 30%">
                            商品类型
                        </td>
                        <td style="width: 30%">
                            类型创建时间
                        </td>
                        <td style="width: 20%">
                            操作选项
                        </td>
                    </tr>
                    <%    
                        if (Model != null)
                        {
                            foreach (var item in Model)
                            {
                    %>
                    <tr onmouseover="currentcolor=this.style.backgroundColor;this.style.backgroundColor='#DEE6FA'"
                        onmouseout="this.style.backgroundColor=currentcolor">
                        <td>
                            <input type="checkbox" value="<%=item.Protypeid %>" name="id" />
                        </td>
                        <td>
                            <%:item.Protypename%>
                        </td>
                        <td>
                            <%:Convert.ToDateTime(item.Prodate).ToString("yyyy-MM-dd")%>
                        </td>
                        <td>
                            <%=Html.ActionLink("修改", "protypetadd", "admin", new { ProTypeId = item.Protypeid }, null)%>
                            <a onclick="javascript:return confirm('是否确认删除')" href='<%=Url.Action("protypetlist", "admin", new { ProTypeId = item.Protypeid })%>'>
                                删除</a>
                        </td>
                    </tr>
                    <%}
                        }
                    %>
                    <tr>
                        <td>
                            <input type="checkbox" id="cball" onclick="selectall(this)" />全选删除
                            <input type="submit" value="确认批量删除" />
                        </td>
                        <td>
                        </td>
                        <td colspan="2">
                        </td>
                    </tr>
                </table>
                <%}
                %>
            </div>
        </fieldset>
        <p style="text-align: center">
            <span style="background: #ffffff; padding: 5px; border: 1px solid #CCCCCC;">
                <%= Html.ActionLink("添加类型", "protypetadd")%></span>
        </p>
    </body>
    </html>
      

  3.   

    这样应该可以了.只是别搞很多HTML很难过滤掉
      

  4.   

    给这组checkbox一个相同的name,比如:chbAbc
    var str = "";
    $("input[name='chbAbc'][checked]").each(function() {  
        var str += $(this).val()+",";
        //AJAX提交
    });