$(function() { $("ul li a").css("cursor", "pointer"); $("ul li a").click(function() { var $ck = $(this).siblings(":checkbox"); if ($ck.attr("name") == "total")//全选 { if ($ck.attr("checked") == false) { $ck.attr("checked", "checked"); $("[name='ck']:checkbox").attr("checked", "checked"); var ff = $ck.val();//获取要执行的函数的字符串 var cc = $ck.get(0);// 将jquery对象 转换为DOM对象 window[ff](cc);//执行字符串的函数 并将当前checkbox对象作为参数 传过去 } else { $ck.attr("checked", ""); $("[name='ck']:checkbox").attr("checked", ""); var ff = $ck.val(); var cc = $ck.get(0); window[ff](cc); } } else//当个选择 { if ($ck.attr("checked") == false) { $ck.attr("checked", "checked"); var s = $ck.val(); var a = $ck.get(0); window[s](a); } else { $ck.attr("checked", ""); var s = $ck.val(); var cb = $ck.get(0); window[s](cb); } } }) })