JQuery对checkbox操作 (循环获取)
2018-10-12 13:51
507 查看
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DemoCheckBox.aspx.cs" Inherits="DemoCheckBox" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
<script src="js/jquery-1.6.min.js" type="text/javascript"></script>
<script type="text/javascript">
jQuery(function($){
//全选
$("#btn1").click(function(){
$("input[name='checkbox']").attr("checked","true");
})
//取消全选
$("#btn2").click(function(){
$("input[name='checkbox']").removeAttr("checked");
})
//选中所有基数
$("#btn3").click(function(){
$("input[name='checkbox']:even").attr("checked","true");
})
//选中所有偶数
$("#btn6").click(function(){
$("input[name='checkbox']:odd").attr("checked","true");
})
//反选
$("#btn4").click(function(){
$("input[name='checkbox']").each(function(){
if($(this).attr("checked"))
{
$(this).removeAttr("checked");
}
else
{
$(this).attr("checked","true");
}
})
})
//或许选择项的值
var aa="";
$("#btn5").click(function(){
$("input[name='checkbox']:checkbox:checked").each(function(){
aa+=$(this).val()
})
document.write(aa);
})
})
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="button" id="btn1" value="全选">
<input type="button" id="btn2" value="取消全选">
<input type="button" id="btn3" value="选中所有奇数">
<input type="button" id="btn6" value="选中所有偶数">
<input type="button" id="btn4" value="反选">
<input type="button" id="btn5" value="获得选中的所有值">
<br>
<input type="checkbox" name="checkbox" value="checkbox1">
checkbox1
<input type="checkbox" name="checkbox" value="checkbox2">
checkbox2
<input type="checkbox" name="checkbox" value="checkbox3">
checkbox3
<input type="checkbox" name="checkbox" value="checkbox4">
checkbox4
<input type="checkbox" name="checkbox" value="checkbox5">
checkbox5
<input type="checkbox" name="checkbox" value="checkbox6">
checkbox6
<input type="checkbox" name="checkbox" value="checkbox7">
checkbox7
<input type="checkbox" name="checkbox" value="checkbox8">
checkbox8
</div>
</form>
</body>
</html>
jquery 循环读取checkbox值
$("input[type=checkbox][checked]").each(function(){ //由于复选框一般选中的是多个,所以可以循环输出
alert($(this).val());
});
您可能感兴趣的文章:
相关文章推荐
- JQuery对checkbox操作 (循环获取)
- JQuery对checkbox操作 (循环获取)
- JQuery对checkbox操作 (循环获取)
- JQuery对checkbox操作 (循环获取)
- JQuery对checkbox操作 (循环获取)
- jquery 循环获取checkBox的值,以及对复选框选中,取消,操作按钮
- jquery 循环获取checkBox的值,以及对复选框选中,取消,操作按钮
- JQuery对checkbox操作 (循环获取)
- jQuery获取checkbox选中项等操作及注意事项
- jquery 操作checkbox的例子(全选,反选,获取选取值...)
- jQuery中获取checkbox选中项等操作及注意事项
- jQuery获取checkbox选中项等操作及注意事项
- jQuery获取checkbox选中项等操作及注意事项
- jquery对表单checkbox复选框的操作例子(全选,反选,获取选取值)
- Jquery操作select,radio,checkBox,获取选中项的值和文本,根据值和文本设置选中项
- jQuery操作复选框checkbox技巧总结 ---- 设置选中、取消选中、获取被选中的值、判断是否选中等
- JQuery对checkbox操作 (循环)
- jQuery获取checkbox选中项等操作及注意事项
- jQuery操作checkbox的例子(全选,反选,获取选取值)【转】
- JQuery实现下拉框的选择 与当CheckBox为服务器控件时如何获取值的操作,实现全选与删除