本文介绍了选中后如何获取Jquey Checkbox的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在html中有一个复选框,并且通过将相同的复选框放在foreach中创建了多个复选框
参考代码如下.
问题:如何获取所有已选中复选框的价值.

I have one checkbox in html and I have created multiple checkboxes by putting same checkbox in foreach
for a reference code is a follows.
Question: How I get value of all checkboxes those are checked.

<div id="friend-list">
    <h3>Grouop Member</h3>               
        <div style="height:190px; width:250px;margin-removed10px; text-align:left " id="Group-list">
 
        <% if (groMoney.Services.UserGroupMemberSevices.get_grpMemberList(groMoney.Services.GroMoneyUserMemberService.getCurrentUser()).Rows.Count != 0)
            {  %>
            <% foreach (System.Data.DataRow MemberData in groMoney.Services.UserGroupMemberSevices.get_grpMemberList(groMoney.Services.GroMoneyUserMemberService.getCurrentUser()).Rows)
               { %>
               <ul>
                   <input id="check-name" type="checkbox" value="<%=MemberData[0]%>" 

                     title="Do you want to select member from group?" name="chk-name" /><%=MemberData[1]%>
               </ul>
            <%} %>
        <%} %>
        </div>
        <div class="lb-content-top">
            <input class="button" style="cursor: pointer;left:20px;top: 2px;" type="button"

                value="View" name="delMember" tabindex="3" title="Delete selection"  önclick="getSelectedMember()" />
        </div>                   
</div>

推荐答案

function getSelectedMember(field, count)
{
  var icount = document.getElementById(count).value;
  for (var i = 0; i <icount; i++)
  {
    if (document.getElementById(field + i).checked == true)
    {
      alert(document.getElementById(field + i).value);
      //You can use this value
     }
   }
}









<div id="friend-list">
               <h3>Grouop Member</h3>
                    <div style="height:190px; width:250px;margin-removed10px; text-align:left " id="Group-list">
         <% if (groMoney.Services.UserGroupMemberSevices.get_grpMemberList(groMoney.Services.GroMoneyUserMemberService.getCurrentUser()).Rows.Count != 0)
            {int i=0; %> 
            <% foreach (System.Data.DataRow MemberData in groMoney.Services.UserGroupMemberSevices.get_grpMemberList(groMoney.Services.GroMoneyUserMemberService.getCurrentUser()).Rows)
               {%>
               <ul>
                   <input id="check-name<%=i%>" type="checkbox" value="<%=MemberData[0]%>"title="Do you want to select member from group?" name="chk-name" /><%=MemberData[1]%>
               </ul>
            <% i++; //Added} %>
         <%} %>
                    </div>
                   <div class="lb-content-top">
<input type="text" id="txt" value="<%=i%>" style="visibility:hidden" /> //ADDED
                     <input class="button" style="cursor: pointer;left:20px;top: 2px;" type="button" value="View" name="delMember" tabindex="3" title="Delete selection"  önclick="getSelectedMember('check-name', 'txt')" />
                    </div>
             </div>





希望对您有帮助.





hope this will help you.


这篇关于选中后如何获取Jquey Checkbox的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 13:59