<div class="codetitle"> <span><a style="CURSOR: pointer" data="84380" class="copybut" id="copybut84380" onclick="doCopy('code84380')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code84380"> <br><gridview id="gvReceipt" runat="server" width="100%" autogeneratecolumns="False" datakeynames="ID" cssclass="Grid"> <br><columns> <br><templatefield> <br><itemtemplate> <br><input type="checkbox" id="chkReceipt" value='<%#Eval("ID") %>' name="chkReceipt"> <br><input id="hdCustomerCode" type="hidden" value='<%#Eval("CustomerCode") %>'> <br><input id="hdCustomerName" type="hidden" value='<%#Eval("Customer") %>'> <br><input class="hdStatus" type="hidden" value='<%#Eval("Department") %>'> <br></itemtemplate> <br></templatefield> <br></columns></gridview> <br> </div> <br>你想取选中的checkbox后面隐藏域中的value,如下: <br><div class="codetitle"> <span><a style="CURSOR: pointer" data="76094" class="copybut" id="copybut76094" onclick="doCopy('code76094')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code76094"> <br>function SelectReceipt() <br>{ <br>var checknum = 0; <br>var customerCode = ""; <br>var type = ""; <br>var url = ""; <br>checknum = $("input:checked").length; <br>if (checknum > 1) <br>{ <br>alert("只能选择一条记录进行收款!"); <br>return false; <br>} <br>else <br>{ <br>alert(checknum); <br>if (checknum == 1) <br>{ <br>customerCode = $("input:checked").next().attr("value"); //通过next()方法取,如果要取再下一个hdCustomerName的值,可以.next().next()。 <br>//customerName = $("input:checked~#hdCustomerName").val();//IE用ID会报错,firefox不会 <br>type = $("input:checked~.hdStatus").attr("value");//或者通过用class的方式取, <br>url = 'PreReceiptDeposit.aspx?customerCode=' + customerCode + '&departmentType=' + type; <br>} <br>else <br>{ <br>url = 'PreReceiptDeposit.aspx?customerCode=' + '' + '&departmentType=' + type; <br>} <br>alert(url); <br>UniversalOpenWindowAndBreak(640, 600, url, 1); <br>return true; <br>} <br>} <br> </div> <br>jQuery--checkbox全选/取消全选 <br><div class="codetitle"> <span><a style="CURSOR: pointer" data="54068" class="copybut" id="copybut54068" onclick="doCopy('code54068')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code54068"> <br> <br> <br><script src="jquery-1.3.2.min.js" type="text/javascript"></script> <br> <br> <br><input type="checkbox" name="chk_list" id="chk_list_1" value="1">1<br> <br><input type="checkbox" name="chk_list" id="chk_list_2" value="2">2<br> <br><input type="checkbox" name="chk_list" id="chk_list_3" value="3">3<br> <br><input type="checkbox" name="chk_list" id="chk_list_4" value="4">4<br> <br><input type="checkbox" name="chk_all" id="chk_all">全选/取消全选 <br><script type="text/javascript"> <BR>$("#chk_all").click(function(){ <BR>$("input[name='chk_list']").attr("checked",$(this).attr("checked")); <BR>}); <BR></script> <br> <br> <br> </div> <br>jQuery.attr 获取/设置对象的属性值,如: <br>$("input[name='chk_list']").attr("checked"); //读取所有name为'chk_list'对象的状态(是否选中) <br>$("input[name='chk_list']").attr("checked",true); //设置所有name为'chk_list'对象的checked为true <br>再如: <br>$("#img_1").attr("src","test.jpg"); //设置ID为img_1的<img alt="JQuery一种取同级值的方式(比如你在GridView中)_jquery" >src的值为'test.jpg' <br>$("#img_1").attr("src"); //读取ID为img_1的<img alt="JQuery一种取同级值的方式(比如你在GridView中)_jquery" >src值 <br>下面的代码是获取上面实例中选中的checkbox的value值: <br><div class="codetitle"> <span><a style="CURSOR: pointer" data="93589" class="copybut" id="copybut93589" onclick="doCopy('code93589')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code93589"> <br><script type="text/javascript"> <BR>//获取到所有name为'chk_list'并选中的checkbox(集合) <BR>var arrChk=$("input[name='chk_list]:checked"); <BR>//遍历得到每个checkbox的value值 <BR>for (var i=0;i<arrChk.length;i++) <BR>{ <BR>alert(arrChk[i].value); <BR>} <BR></script> <br> </div> <br>下面是用$.each()遍历的代码: <br><div class="codetitle"> <span><a style="CURSOR: pointer" data="75026" class="copybut" id="copybut75026" onclick="doCopy('code75026')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code75026"> <br><script type="text/javascript"> <BR>var arrChk=$("input[name='chk_list']:checked"); <BR>$(arrChk).each(function(){ <BR>window.alert(this.value); <BR>}); <BR>}); <BR></script> <br> </div>