日期:2014-05-16  浏览次数:20368 次

求助:jQuery关于checkbox里的checked全选/反选的问题

多次全选/反选之后,页面没有及时刷新,出现了代码为checked,而页面未被勾选的问题。
如果选中客户管理checkbox,则以下子checkbox都要选中,否则都不选中。只要有一个子checkbox被选中,客户管理checkbox就要被选中。




/**
 * Created with IntelliJ IDEA.
 * User: H.Kunping
 * Date: 13-9-13
 * Time: 下午10:50
 * To change this template use File | Settings | File Templates.
 */

function goSelected(id){

    var arrayValue = id.split("_");

    if(arrayValue[0]!=arrayValue[1]){
        var superid = arrayValue[0]+"_"+arrayValue[0];
        if ($("#"+id)[0].checked){
            $("#"+superid).attr("checked", "checked");
        } else {
            var flag = false;
            var $child = $("input[type=checkbox][id^="+arrayValue[0]+"]:not([id$="+arrayValue[0]+"])");
            $child.each(function(){
                if(this.checked) {
                    flag=true;
                    return;
                }
            });
            if(!flag){
                $("#"+superid).attr("checked", null);
            }
        }
    }

    if(arrayValue[0]==arrayValue[1]){
        if ($("#"+id)[0].checked){
            $("input[type=checkbox][id^="+arrayValue[0]+"]").attr("checked", "checked");
        } else {