jquery如何獲取checkbox,並判斷是否選中
http://wenda.so.com/q/1378497447071815
<div id="divId" class="divTable">
<div class="tableBody">
<ul ><li ><input type="checkbox" value="501" ></li></ul>
</div>
</div>
$("input[type='checkbox']").attr('value')
返回結果:501
$("input[type='checkbox']").is(':checked')
返回結果:選中=true,未選中=false
jquery 遍歷checkbox
http://www.cnblogs.com/wmymtx/archive/2011/12/15/2289150.html
jQuery對checkbox的操作
http://blog.csdn.net/hu_shengyang/article/details/6437729
$(document).ready(function(){
//checkbox全選
$('#btn1').click(function(){
$("[name = 'checkbox']").attr('checked',true);
});
//checkbox取消選擇
$('#btn2').click(function(){
$("[name = 'checkbox']").attr('checked',false);
});
//checkbox反選
$('#btn3').click(function(){
$("[name = 'checkbox']").each(function(){
if($(this).attr('checked')){
$(this).removeAttr('checked');
}else{
$(this).attr('checked',true);
}
});
});
//checkbox選中偶數行
$('#btn4').click(function(){
$("[name = 'checkbox']:even").attr('checked',true);
});
//設置table2偶數行背景色
$("#table2 tr:even").css("background-color","#DBE5F1");
//鼠標移上時添加行背景色 css類hover中定義的是背景色,也可定義其他
$('#table2 tbody tr',this).mouseover(function(){
$(this).find('td').addClass("hover");
});
//鼠標移去時恢復行背景色
$('#table2 tbody tr',this).mouseout(function(){
$(this).find('td').removeClass("hover");
});
//點擊添加按鈕跳轉頁面
$('#btnAddInList').click(function(){
var url="/gis/supplyArea/addInListSupplyArea.do";
//alert(url);
$.ajax({
url:url,
complete:function(){location.href =url}//完成後跳轉的頁面
});
});
//刪除選定的複選框的記錄
$('#btnDel').click(function(){
var supplyAreaIds = '';
$("[type='checkbox'][name='checkbox']:checked").each(function(){
supplyAreaIds+= $(this).val()+",";
});
//alert(supplyAreaIds);
var url="/gis/supplyArea/deldeteSupplyArea.do";
$.ajax({
type:'POST',
contentType: "application/x-www-form-urlencoded;charset=utf-8",
url:url,
data:{ids:supplyAreaIds},
dataType:"text",
//成功後
success:function(msg){
alert(supplyAreaIds+" 刪除成功!");
},
//完成後
complete:function(){
$("[name = 'checkbox']").attr('checked',false);//取消選擇
location.reload();//刷新
}
});
});
});