JQuery一种取同级值的方式(比如你在GridView中) - Web前端
作者:98wpeu发布时间:2026-07-30分类:网页前端技术浏览:63
导读:复制代码代码如下:<asp:GridViewID="gvReceipt"runat="server"width="100%"AutoGenerateColumns=...
复制代码 代码如下:
<asp:GridView ID="gvReceipt" runat="server" width="100%" AutoGenerateColumns="false" dataKeyNames="ID" CSSclass="Grid" >
<Columns>
<asp:TemplateFIEld>
<ItemTemplate >
<inputtype="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,如下:
复制代码 代码如下:
functionselectReceipt()
{
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>
<asp:GridView ID="gvReceipt" runat="server" width="100%" AutoGenerateColumns="false" dataKeyNames="ID" CSSclass="Grid" >
<Columns>
<asp:TemplateFIEld>
<ItemTemplate >
<inputtype="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,如下:
复制代码 代码如下:
functionselectReceipt()
{
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简单验证上传文件大小及类型的方法 - Web前端
- jquery 获取select数组与name数组长度的实现代码 - Web前端
- jQuery插件扩展extend的简单实现原理 - Web前端
- jQuery简单实现tab选项卡切换效果 - Web前端
- 基于jQuery实现点击列表加载更多效果 - Web前端
- jQuery基于$.ajax设置移动端click超时处理方法 - Web前端
- 基于jQuery插件实现点击小图显示大图效果 - Web前端
- 使用JQuery 加载页面时调用JS的实现方法 - Web前端
- 底部悬浮通栏可以关闭广告位的实现方法 - Web前端
- jQuery调用WebMethod(PageMethod) NET2.0的方法 - Web前端
- 网页前端技术排行
-
- 1[Web前端]用javascript实现默认图片替代未显示的图片 - Web前端
- 2分析Iconfont-阿里巴巴矢量常用图标库 - Web前端
- 3jQuery实例教程:制作网页中可折叠的面板 - Web前端
- 4【第六章】Foundation之按钮和下拉功能 - Web前端
- 5基于jquery的滚动条滚动固定div(附演示下载) - Web前端
- 6jQuery编写widget的一些技巧分享 - Web前端
- 7分享精心挑选的12款优秀jQuery Ajax分页插件和教程 - Web前端
- 8jQuery实现鼠标移到元素上动态提示消息框效果 - Web前端
- 9在Mac/PC上远程调试iPhone/iPad上的网页 - Web前端
- 最近发表
-
- WordPress随机显示特色图片插件:Random Post Thumbnails
- KeePass实现Chrome浏览器自动填充密码方法一
- LNMP一键包nginx 301强制跳转到https教程
- KeePass实现Chrome浏览器自动填充密码方法二
- #建站# 免费的VPS管理软件Xshell8/Xftp8中文版下载
- 使用Xshell 8连接VPS教程_电脑登录vps的方法
- WordPress评论界面添加烟花????效果
- 不同浏览器书签同步方案:坚果云+Floccus_详细使用教程
- iOS端KeePassXC客户端APP:Strongbox Password Safe
- 给WordPress评论中的Gravatar头像图片添加ALT属性


