jquery 中获取所有选中的checkbox的用法
2016-03-16 11:34
645 查看
以往还错误的把$("input[type='checkbox'][checked]") 是正确的用法,奇怪的是:这样用之前确实是好用的,单当我页面中的html内容超过1000行时,就不好使了,后来我这样的问题,才发现原来我的使用方法一直是错误的。
修改为:
$("input:checkbox[name='the checkbox name']:checked")
如果是在某一些标签下查找的话,为了防止查找到table #tbTemplate元素以外的checkbox:checked,我们可以这样来限制:
$("table#tbTemplate input:checkbox[name='the checkbox name']:checked")
原生态的用法:
$($("table#tbTemplate input[type='checkbox']"),function(i,checkbox){
if(checkbox.checked){
// keep the state. or log this checked......
}
});
两种方法比较:前者的效率更高。
以后要牢记了,自警!
select恢复到默认状态: $("select#select1").attr("selected","");
清空下拉列表: $("select#select1").empty();
设置选中项:
$($("select#select1 option"), function(i, option){
if(option.value="my select option1"){// we also can using the option.text to map the option
option.selected=true;
}
});
修改为:
$("input:checkbox[name='the checkbox name']:checked")
如果是在某一些标签下查找的话,为了防止查找到table #tbTemplate元素以外的checkbox:checked,我们可以这样来限制:
$("table#tbTemplate input:checkbox[name='the checkbox name']:checked")
原生态的用法:
$($("table#tbTemplate input[type='checkbox']"),function(i,checkbox){
if(checkbox.checked){
// keep the state. or log this checked......
}
});
两种方法比较:前者的效率更高。
以后要牢记了,自警!
select恢复到默认状态: $("select#select1").attr("selected","");
清空下拉列表: $("select#select1").empty();
设置选中项:
$($("select#select1 option"), function(i, option){
if(option.value="my select option1"){// we also can using the option.text to map the option
option.selected=true;
}
});
相关文章推荐
- 基于jQuery Tipso插件实现消息提示框特效
- 简单的jQuery表单正则验证和提交
- Jquery技巧(必须掌握)
- JQUERY 插件开发——LAZYLOADIMG(预加载和延迟加载图片)
- Jquery轮播图片
- 精心挑选的12款优秀 jQuery Ajax 分页插件和教程
- jQuery插件开发的模式和结构
- Struts2+JQuery+Json实例
- jQuery插件开发精品教程,让你的jQuery提升一个台阶
- 锋利的JQuery 学习笔记
- jquery.qrcode笔记
- jquery uploadify上传文件404,500错误
- jQuery 遍历 each()方法
- django用jquery的ajax提交表单,中间件的CsrfViewMiddleware问题
- JQuery概述和一个简单案例
- 利用jquery控制checkbox被选中
- jquery笔记
- ajax(通过jQuery实现)
- jquery很好的学习网站
- jquery判断字符在不在数组中