$(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();//刷新 } }); }); });
本文转自:http://blog.csdn.net/hu_shengyang/article/details/6437729