使用JQuery获取被选中的checkbox的value值
2017-07-05 09:52
555 查看
以下为使用JQuery获取input checkbox被选中的值代码:
<html>
<head>
<meta charset="gbk">
<!-- 引入JQuery -->
<script src="jquery-1.3.1.js" type="text/javascript"></script>
</head>
<body>
<input type="checkbox" value="橘子" name="check">橘子1</input>
<input type="checkbox" value="香蕉" name="check">香蕉1</input>
<input type="checkbox" value="西瓜" name="check">西瓜1</input>
<input type="checkbox" value="芒果" name="check">芒果1</input>
<input type="checkbox" value="葡萄" name="check">葡萄1</input>
<input type="button" value="方法1" id="b1">
<input type="button" value="方法2" id="b2">
</body>
<script>
//方法1
$("#b1").click(function(){
//$('input:checkbox:checked') 等同于 $('input[type=checkbox]:checked')
//意思是选择被选中的checkbox
$.each($('input:checkbox:checked'),function(){
window.alert("你选了:"+
$('input[type=checkbox]:checked').length+"个,其中有:"+$(this).val());
});
});
//方法2
$("#b2").click(function(){
$.each($('input:checkbox'),function(){
if(this.checked){
window.alert("你选了:"+
$('input[type=checkbox]:checked').length+"个,其中有:"+$(this).val());
}
});
});
</script>
</html>
转载地址:http://www.cnblogs.com/td960505/p/6123510.html
<html>
<head>
<meta charset="gbk">
<!-- 引入JQuery -->
<script src="jquery-1.3.1.js" type="text/javascript"></script>
</head>
<body>
<input type="checkbox" value="橘子" name="check">橘子1</input>
<input type="checkbox" value="香蕉" name="check">香蕉1</input>
<input type="checkbox" value="西瓜" name="check">西瓜1</input>
<input type="checkbox" value="芒果" name="check">芒果1</input>
<input type="checkbox" value="葡萄" name="check">葡萄1</input>
<input type="button" value="方法1" id="b1">
<input type="button" value="方法2" id="b2">
</body>
<script>
//方法1
$("#b1").click(function(){
//$('input:checkbox:checked') 等同于 $('input[type=checkbox]:checked')
//意思是选择被选中的checkbox
$.each($('input:checkbox:checked'),function(){
window.alert("你选了:"+
$('input[type=checkbox]:checked').length+"个,其中有:"+$(this).val());
});
});
//方法2
$("#b2").click(function(){
$.each($('input:checkbox'),function(){
if(this.checked){
window.alert("你选了:"+
$('input[type=checkbox]:checked').length+"个,其中有:"+$(this).val());
}
});
});
</script>
</html>
转载地址:http://www.cnblogs.com/td960505/p/6123510.html
相关文章推荐
- 使用JQuery获取被选中的checkbox的value值 以及全选、反选
- JQuery获取被选中的checkbox的value值
- 使用JQuery获取被选中的checkbox的value值
- 使用Linq绑定三级treeview 并获取被选中的checkbox所对应的text值
- jQuery获取CheckBox选择的Value值
- JQuery 获取checkbox被选中的值
- jQuery操作复选框checkbox技巧总结 ---- 设置选中、取消选中、获取被选中的值、判断是否选中等
- Jquery获取页面中checkbox组中被选中的值
- 使用 jquery 获取一组或者单个 checkbox 的选中状态的id
- jquery获取所有被选中checkbox
- 使用 jquery 获取一组或者单个 checkbox 的选中状态的值
- jQuery获取checkboxlist的value值
- Jquery获取页面中checkbox组中被选中的值
- 如何使用Jquery获取Form表单中被选中的radio值
- JQuery获取被选中复选框checkbox的个数
- jQuery获取checkboxlist中的value值
- jquery获取被选中的checkbox
- 使用 Jquery 选中获取 checkbox radio 和 select的 value 和 text
- 使用 jquery 获取一组或者单个 checkbox 的选中状态的id
- 使用jQuery判断checkbox是否被选中