jquery判断复选框是否被选中的方法
作者:bea
jquery 判断复选框是否选中以及如何选中的问题做一下总结。 进入正题,还是当页面有如下一组复选框的时候: <input type="checkbox" name="fruit" value="apple" />苹果 <input type="checkbox" name="fruit" value="orange" />橘子 <input type="checkbox" name="fruit" value="banana" />
jquery 判断复选框是否选中以及如何选中的问题做一下总结。 进入正题,还是当页面有如下一组复选框的时候:
<input type="checkbox" name="fruit" value="apple" />苹果
<input type="checkbox" name="fruit" value="orange" />橘子
<input type="checkbox" name="fruit" value="banana" />香蕉
<input type="checkbox" name="fruit" value="grape" />葡萄
那么使用 Jquery 获取 name=fruit 的一组复选框的值的方法如下:
var checkVal='';
$("input[name='fruit']:checkbox").each(function(){
if($(this).attr('checked')){
checkVal+=$(this).val()+',';
}
})
判断 name=fruit 组的复选框是否有被选中的选项:
var flag=false;
$("input[name='fruit']:checkbox").each(function(){
if($(this).attr('checked')){
flag=true;
}
})
if(flag){
alert('有被选中');
}else{
alert('没有选中任何选项');
}
以上就是jquery判断复选框是否被选中的方法,希望对大家的学习有所帮助,还有用js获取的,请参考《JS判断复选框是否选中实例》
有用 | 无用
<input type="checkbox" name="fruit" value="apple" />苹果
<input type="checkbox" name="fruit" value="orange" />橘子
<input type="checkbox" name="fruit" value="banana" />香蕉
<input type="checkbox" name="fruit" value="grape" />葡萄
那么使用 Jquery 获取 name=fruit 的一组复选框的值的方法如下:
var checkVal='';
$("input[name='fruit']:checkbox").each(function(){
if($(this).attr('checked')){
checkVal+=$(this).val()+',';
}
})
判断 name=fruit 组的复选框是否有被选中的选项:
var flag=false;
$("input[name='fruit']:checkbox").each(function(){
if($(this).attr('checked')){
flag=true;
}
})
if(flag){
alert('有被选中');
}else{
alert('没有选中任何选项');
}
以上就是jquery判断复选框是否被选中的方法,希望对大家的学习有所帮助,还有用js获取的,请参考《JS判断复选框是否选中实例》
有用 | 无用
猜你喜欢
您可能感兴趣的文章:
- JS+CSS实现分类动态选择及移动功能效果代码
- 谈谈Jquery中的children find 的区别有哪些
- JS实现的简洁纵向滑动菜单(滑动门)效果
- JS实现的左侧竖向滑动菜单效果代码
- jQuery实现ctrl+enter(回车)提交表单
- JS实现网页游戏中滑块响应鼠标点击移动效果
- 在JavaScript中如何解决用execCommand(
- 简单谈谈Javascript中类型的判断
- AngularJS 实现按需异步加载实例代码
- 学习javascript的闭包,原型,和匿名函数之旅
- Javascript中的数据类型之旅
- 谈谈JavaScript自定义回调函数
- JS实现的网页背景闪电闪烁效果代码
- JavaScript实现点击按钮切换网页背景色的方法
- JavaScript实现的背景自动变色代码
- jQuery实现有动画淡出效果的二级折叠菜单代码
- 利用jQuery和CSS将背景图片拉伸
- 基于jQuery实现的菜单切换效果
- javascript判断复选框是否选中的方法