JQuery一种取同级值的方式(比如你在GridView中) - Web前端
作者:98wpeu发布时间:2026-07-30分类:网页前端技术浏览:1
导读:复制代码代码如下:<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>
- 上一篇:20个最新的jQuery插件 - Web前端
- 下一篇:已经是最后一篇了
相关推荐
- 修改jQuery Validation里默认的验证方法 - Web前端
- jQuery源码分析-05异步队列 Deferred 使用介绍 - Web前端
- 20个最新的jQuery插件 - Web前端
- 远离JS灾难css灾难之 js私有函数和css选择器作为容器 - Web前端
- jquery.fileEveryWhere.js 一个跨浏览器的file显示插件 - Web前端
- editable.js 基于jquery的表格的编辑插件 - Web前端
- Json2Template.js 基于jquery的插件 绑定JavaScript对象到Html模板中 - Web前端
- 读jQuery之十四 (触发事件核心方法) - Web前端
- 基于Jquery的文字自动截取(提供源代码) - Web前端
- 关于hashchangebroker和statehashable的补充文档 - Web前端
- 网页前端技术排行
-
- 1[Web前端]用javascript实现默认图片替代未显示的图片 - Web前端
- 2分析Iconfont-阿里巴巴矢量常用图标库 - Web前端
- 3【第六章】Foundation之按钮和下拉功能 - Web前端
- 4jQuery实例教程:制作网页中可折叠的面板 - Web前端
- 5基于jquery的滚动条滚动固定div(附演示下载) - Web前端
- 6jQuery编写widget的一些技巧分享 - Web前端
- 7jQuery实现鼠标移到元素上动态提示消息框效果 - Web前端
- 8在Mac/PC上远程调试iPhone/iPad上的网页 - Web前端
- 9分享精心挑选的12款优秀jQuery Ajax分页插件和教程 - 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属性


