博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Jquery 复选框取值赋值
阅读量:2062 次
发布时间:2019-04-29

本文共 1232 字,大约阅读时间需要 4 分钟。

1. 获取单个checkbox选中项(三种写法):$("input:checkbox:checked").val() $("input:[type='checkbox']:checked").val(); $("input:[name='ck']:checked").val(); 2. 获取多个checkbox选中项:$('input:checkbox').each(function() {
if ($(this).attr('checked') ==true) {
alert($(this).val()); } }); 3. 设置第一个checkbox 为选中值:$('input:checkbox:first').attr("checked",'checked'); $('input:checkbox').eq(0).attr("checked",'true'); 4. 设置最后一个checkbox为选中值:$('input:radio:last').attr('checked', 'checked'); $('input:radio:last').attr('checked', 'true');5. 根据索引值设置任意一个checkbox为选中值:$('input:checkbox).eq(索引值).attr('checked', 'true');索引值=0,1,2.... $('input:radio').slice(1,2).attr('checked', 'true'); 6. 选中多个checkbox: 同时选中第1个和第2个的checkbox:$('input:radio').slice(0,2).attr('checked','true'); 7. 根据Value值设置checkbox为选中值:$("input:checkbox[value='1']").attr('checked','true');8. 删除Value=1的checkbox:$("input:checkbox[value='1']").remove();9. 删除第几个checkbox:$("input:checkbox").eq(索引值).remove();索引值=0,1,2.... 10.遍历checkbox:$('input:checkbox').each(function (index, domEle) {
//写入代码 });11.全部选中$('input:checkbox').each(function() {
$(this).attr('checked', true); });12.全部取消:$('input:checkbox').each(function () {
$(this).attr('checked',false); });

转载地址:http://skllf.baihongyu.com/

你可能感兴趣的文章
使用 wrk 压测并精细控制并发请求量
查看>>
Ceph 故障排查笔记 | 万字经验总结
查看>>
使用 Go 从零开始实现 CNI 可还行?
查看>>
KubeSphere 3.1.0 GA:混合多云走向边缘,让应用无处不在
查看>>
Containerd 1.5 发布:重磅支持 docker-compose!
查看>>
基于 Kubernetes 的 Spring Could 微服务 CI/CD 实践
查看>>
5.15 相约上海!2021 年度首届云原生 Meetup | KubeSphere & Friends
查看>>
使用 Cilium 作为网络插件部署 K8s + KubeSphere
查看>>
万变不离其宗,性能优化也有章可循
查看>>
别再乱用 Prometheus 联邦了,分享一个 Prometheus 高可用新方案
查看>>
Litmus 实践:让群魔在混沌中乱舞,看 K8s 能撑到何时
查看>>
Prometheus 存储层的演进
查看>>
Kubernetes 边缘节点抓不到监控指标?试试这个方法!
查看>>
不对全文内容进行索引的 Loki 到底优秀在哪里
查看>>
太强大了!这些 Go 的难点问题都能解决!
查看>>
万字长文:K8s 创建 pod 时,背后到底发生了什么?
查看>>
后云原生时代,Kubernetes:你看我还有机会吗?
查看>>
Wintun:一款惊艳的 WireGuard 虚拟网卡接口驱动
查看>>
个人学习方法分享
查看>>
时隔多年。。终于有一款云原生消息系统出仕了!
查看>>