JQuery一种取同级值的方式(比如你在GridView中)
2012-03-15 00:00
591 查看
<asp:GridView ID="gvReceipt" runat="server" Width="100%" AutoGenerateColumns="False" DataKeyNames="ID" CssClass="Grid" > <Columns> <asp:TemplateField> <ItemTemplate > <input type="checkbox" id="chkReceipt" value='<%#Eval("ID") %>' name="chkReceipt" /> <input id="hdCustomerCode" type="hidden" value='<%#Eval("CustomerCode") %>' /> <input id="hdCustomerName" type="hidden" value='<%#Eval("Customer") %>' /> <input class="hdStatus" type="hidden" value='<%#Eval("Department") %>' /> </ItemTemplate> </asp:TemplateField> </asp:GridView>
你想取选中的checkbox后面隐藏域中的value,如下:
function SelectReceipt() { var checknum = 0; var customerCode = ""; var type = ""; var url = ""; checknum = $("input:checked").length; if (checknum > 1) { alert("只能选择一条记录进行收款!"); return false; } else { alert(checknum); if (checknum == 1) { customerCode = $("input:checked").next().attr("value"); //通过next()方法取,如果要取再下一个hdCustomerName的值,可以.next().next()。 //customerName = $("input:checked~#hdCustomerName").val();//IE用ID会报错,firefox不会 type = $("input:checked~.hdStatus").attr("value");//或者通过用class的方式取, url = 'PreReceiptDeposit.aspx?customerCode=' + customerCode + '&departmentType=' + type; } else { url = 'PreReceiptDeposit.aspx?customerCode=' + '' + '&departmentType=' + type; } alert(url); UniversalOpenWindowAndBreak(640, 600, url, 1); return true; } }
jQuery--checkbox全选/取消全选
<html> <head> <script src="jquery-1.3.2.min.js" type="text/javascript"></script> </head> <body> <input type="checkbox" name="chk_list" id="chk_list_1" value="1" />1<br /> <input type="checkbox" name="chk_list" id="chk_list_2" value="2" />2<br /> <input type="checkbox" name="chk_list" id="chk_list_3" value="3" />3<br /> <input type="checkbox" name="chk_list" id="chk_list_4" value="4" />4<br /> <input type="checkbox" name="chk_all" id="chk_all" />全选/取消全选 <script type="text/javascript"> $("#chk_all").click(function(){ $("input[name='chk_list']").attr("checked",$(this).attr("checked")); }); </script> </body> </html>
jQuery.attr 获取/设置对象的属性值,如:
$("input[name='chk_list']").attr("checked"); //读取所有name为'chk_list'对象的状态(是否选中)
$("input[name='chk_list']").attr("checked",true); //设置所有name为'chk_list'对象的checked为true
再如:
$("#img_1").attr("src","test.jpg"); //设置ID为img_1的<img>src的值为'test.jpg'
$("#img_1").attr("src"); //读取ID为img_1的<img>src值
下面的代码是获取上面实例中选中的checkbox的value值:
<script type="text/javascript"> //获取到所有name为'chk_list'并选中的checkbox(集合) var arrChk=$("input[name='chk_list]:checked"); //遍历得到每个checkbox的value值 for (var i=0;i<arrChk.length;i++) { alert(arrChk[i].value); } </script>
下面是用$.each()遍历的代码:
<script type="text/javascript"> var arrChk=$("input[name='chk_list']:checked"); $(arrChk).each(function(){ window.alert(this.value); }); }); </script>
相关文章推荐
- JQuery一种取同级值的方式 比如你在GridView中如下
- JQuery一种取同级值的方式(比如你在GridView中)
- JQuery一种取同级值的方式
- 一种jquery插件方式的分页
- Jquery-select-处理二级联动的一种简单方式
- 编写jquery插件的一种方式
- jquery 异步加载,懒加载图片一种方式
- 今天在研究jquery用ajax提交form表单中得数据时,学习到了一种新的提交方式
- 用jQuery实现的一种网页内容呈现方式
- jquery实现异步加载图片(懒加载图片一种方式)
- GridView的另外一种分页方式,可提高加载速度
- js的String变量的用法,对jquery的append的一种替代方式
- IPhone中创建线程的令一种简单方式
- 实战MEF(1):一种不错的扩展方式
- 一种不错的扩展方式
- [解决办法]Apache服务启动失败:以一种访问权限不允许的方式做了一个访问套接字的尝试
- ajax jquery ssh实现数据异步方式验证
- 微服务的一种开源实现方式——dubbo+zookeeper
- 一种让UITableView的数据从下往上增长的方式
- asp.net+jquery Gridview的多行拖放, 以及跨控件拖放