选中所有项目后,Select All必须处于Ticked状态

时间:2016-12-16 06:59:00

标签: javascript jquery html struts

我怀疑在检查所有项目时,Select All必须处于Ticked状态。但是当我选择所有项目时,复选框未显示为勾选。

以下是我的代码。

 if (reportsAutoCmpAdgrpGrpCol.getCount() > 0 && mPpc != 0) {
            html.append("<div id='semWklyTab2'  style='height: 400px;overflow-y:scroll'>");
            html.append("<input type='checkbox' id='msnCmpHead'>Select All");
            html.append("&nbsp;&nbsp;&nbsp;");
            html.append("<input type='textbox' id='msnSearchCamp' name='msnSearchCamp' value='' size='20'>");
            html.append("<input type='button' value='Search' onclick=msnSearch('").append(gPpc).append("','").append(mPpc).append("','").append(yPpc).append("','").append(grpId).append("','msnSearchCamp')>");

            html.append("<div class='activeCmpMsn activeCmp'>");
            buildCmpGrpTbl = buildCmpGrpTbl(iterator, grpId, mPpc, "Active", campaignGroupIds);
            html.append(buildCmpGrpTbl);
            html.append("</div>");
            iterator = reportsAutoCmpAdgrpGrpCol.getIterator();
            html.append("<div class='pausedCmpMsn pausedCmp'>");
            buildCmpGrpTbl = buildCmpGrpTbl(iterator, grpId, mPpc, "Paused", campaignGroupIds);
            html.append(buildCmpGrpTbl);
            html.append("</div>");
            html.append("</div>");
        }

以下是buildCmpGrpTbl

的功能
    public StringBuilder buildCmpGrpTbl(Iterator iterator, long grpId, long ppcId, String status, HashMap<Long, Long> campaignGroupIds) {
    StringBuilder html = new StringBuilder();
    GroupingInfo groupInfo; 
    html.append("<table>");
    while (iterator.hasNext()) {
        groupInfo = (GroupingInfo) iterator.next();
        if (groupInfo.getBytComponentType() == CommonConstants.CAMPAIGN && groupInfo.getLngPpcId() == ppcId) {
            if (groupInfo.getStrStatus().contains(status)) {
                html.append("<tr class='trStyle' id = 'test'>");
                html.append("<td align='center' style='line-height:26px;'>");
                html.append("<input type='checkbox' name='campaignId'");
                if (groupInfo.getLngGroupId() == grpId) {
                    html.append(" checked='checked'");
                    campaignGroupIds.put(groupInfo.getLngCampaignId(), groupInfo.getLngPpcId());
                }
                html.append(" value='").
                        append(groupInfo.getLngCampaignId()).append(",").append(groupInfo.getLngSeCampaignId()).append(",").append(ppcId).
                        append("' onclick='hideShowImg(").append(groupInfo.getLngCampaignId()).append(")'/>");
                html.append("</td>");
                html.append("<td class='").append(status).append("' style='line-height:26px;'>");
                html.append("<img alt='Click here to drill down to adgroup data' title='Click here to drill down to adgroup data' src='./Images/Plus Icon.PNG' ");
                if (groupInfo.getLngGroupId() == grpId) {
                    html.append("style='cursor: pointer;display:none'");
                } else {
                    html.append("style='cursor: pointer'");
                }
                html.append(" id=").append(groupInfo.getLngCampaignId()).append(" class='plusImgCmp' "
                        + "onclick=loadAdgrpGrpsForPpc('rprtAutoAdgrpGroups',").append(ppcId).append(",").append(groupInfo.getLngCampaignId()).append(",").append(grpId).append(") />");
                html.append("&nbsp;&nbsp;").append(groupInfo.getStrCmp_Adgrp_Name().replaceAll("\"", "''"));
                html.append("</td>");
                html.append("</tr>");
            }
        }
    }
    html.append("</table>");
    return html;
}

我的html是

<s:multibox property="sheets" styleClass="wkRprts"  value='<%="" + AutoReportConstants.PERFORMANCE_SUMMARY_REPORT_WEEKLY%>' onclick="loadCmps('504',this)"/>SEM Weekly
                                                                                                <img src="./Images/edit.png" alt="Edit Label" title="Edit Label" id ="semWkEdt" style="vertical-align: middle;cursor: pointer;display: none" onclick="loadCmps('504','Edit')">

并且加载元素是

function loadCmps(grpId,cur){
if(cur.checked||cur=='BrndNonBrnd'||cur=='NewGrp'||cur=='Edit'){
    var gAcc=0,mAcc=0,yAcc=0,gPpc,mPpc,yPpc;
    gAcc=gleMsnCnt(2);
    mAcc=gleMsnCnt(3);
    yAcc=gleMsnCnt(10);
    if(gAcc==0&&mAcc==0&&yAcc==0){
        alert("Please select atleast one Account to proceed.");
        cur.checked=false;
        return false;
    }else if(mAcc>1||gAcc>1 || yAcc>1){
        alert("For one template the user is allowed to select One Google,One Bing and One Yahoo Gemini Accounts per client");
        cur.checked=false;
        return false;
    }else{
        $(".wkRprts").attr("disabled", "true");
        $( "#semWklyDiv" ).tabs();
        $( "#semWklyDiv" ).tabs("destroy");
        $( "#semWklyDiv" ).tabs();
        gPpc=getSelPpc(2);
        mPpc=getSelPpc(3);
        yPpc=getSelPpc(10);
        $("#semWklyTab1").html("<div class='progressBarDiv'>Please wait while the campaigns are loading...<div class='progressBar'><div class='ui-progress-label ui-progressbar-overlay'></div></div></div>");
        $("#semWklyTab2").html("<div class='progressBarDiv'>Please wait while the campaigns are loading...<div class='progressBar'><div class='ui-progress-label ui-progressbar-overlay'></div></div></div>");
        $("#semWklyTab3").html("<div class='progressBarDiv'>Please wait while the campaigns are loading...<div class='progressBar'><div class='ui-progress-label ui-progressbar-overlay'></div></div></div>");
        $( ".progressBar" ).progressbar({
            value: false
        });
        $( "#semWklyDiv" ).show();
        $("#semWklyDiv")[0].scrollIntoView();
        loadCmpAdgrpGrpsForPpcs("AutoRprtsCmpAdgrpGroups",gPpc,mPpc,yPpc,grpId);
    }
}else{
    $( "#semWklyDiv" ).hide();
}

// resizeIframe('#landingPage'); }

1 个答案:

答案 0 :(得分:0)

尝试这个jQuery事件

$(document).on('change','input[name='campaignId']', function(){
    if( $('input[name='campaignId']:checked').length == $('input[name='campaignId']').length ) {
        $('#msnCmpHead').prop('checked', true);
    } else {
        $('#msnCmpHead').prop('checked', false);
    }
})

如果您有反向要求,请检查此链接
JSFiddle

<强>建议
如果您将Class添加到name='campaignId

,那就太棒了