[TOC]

JSP二级下拉框的一种简单写法


  • 舆情分类*





    <%—


    **选择分类**

    —%>




    <input type=”checkbox” class=”chkno asd${opinionList.opinionId}” name=”opinionId” value=”${opinionList.opinionId}” <%—style=”display:none”—%>/>${opinionList.opinionName}








    • <input id=”asd${opinionList.opinionId}” class=”asd${childrenList.opinionChildId}” name=”opinionChildId” type=”checkbox” value=”${childrenList.opinionChildId}” <%—onclick=”getblink(‘${dept.deptId}’,’${depttt.deptId }’)”—%> />${childrenList.opinionChildName}













  • var checkboxValue=””;
    var checkboxText=””;
    var checkboxOneValue=new Array();
    var checkboxTwoValue=new Array();
    var checkboxOneText=new Array();
    var checkboxTwoText=new Array();
    var checkboxOneStr=document.getElementsByName(“opinionId”);
    var checkboxTwoStr=document.getElementsByName(“opinionChildId”);
    var opinionList=${requestScope.opinion.opinion};
    //debugger
    for (let f=0; f<checkboxOneStr.length;f++) {
    if(checkboxOneStr[f].checked){
    //id
    checkboxOneValue.push(checkboxOneStr[f].value);
    //name
    checkboxOneText.push(checkboxOneStr[f].nextSibling.nodeValue);
    }
    }
    for (let f=0; f<checkboxTwoStr.length;f++) {
    if(checkboxTwoStr[f].checked){
    //id
    checkboxTwoValue.push(checkboxTwoStr[f].value);
    //name
    checkboxTwoText.push(checkboxTwoStr[f].nextSibling.nodeValue);
    }
    }
    //一级项二级项皆选中情况
    for (let j = 0; j <checkboxOneValue.length ; j++) {
    for (let i = 0; i <opinionList.length ; i++) {
    if (opinionList[i].opinionId == checkboxOneValue[j]){
    for (let k = 0; k < opinionList[i].children.length; k++) {
    for (let m = 0; m < checkboxTwoValue.length; m++) {
    if (opinionList[i].children[k].opinionChildId == checkboxTwoValue[m]){
    checkboxText += opinionList[i].opinionName + “-“;
    checkboxText +=checkboxTwoText[m] + “,”;
    checkboxValue += checkboxTwoValue[m] + “,”;
    }
    }
    }
    }
    }
    }
    //一级项未选中情况
    for (let i = 0; i <opinionList.length ; i++) {
    debugger
    if(checkboxOneValue.indexOf(opinionList[i].opinionId+””)<0) {
    for (let k = 0; k < opinionList[i].children.length; k++) {
    for (let m = 0; m < checkboxTwoValue.length; m++) {
    if (opinionList[i].children[k].opinionChildId == checkboxTwoValue[m]) {
    checkboxText += opinionList[i].opinionName + “-“;
    checkboxText +=checkboxTwoText[m] + “,”;
    checkboxValue += checkboxTwoValue[m] + “,”
    }
    }
    }
    }
    }
    checkboxValue = (checkboxValue.substring(checkboxValue.length - 1) == ‘,’) ? checkboxValue.substring(0, checkboxValue.length - 1) : checkboxValue;
    checkboxText = (checkboxText.substring(checkboxText.length - 1) == ‘,’) ? checkboxText.substring(0, checkboxText.length - 1) : checkboxText;
    $(“#opinionIds”).val(checkboxValue);
    $(“#opinionNames”).val(checkboxText)


    **<input type=”hidden” id=”opinionNames” name=”opinionNames” value=””/

    //点击一级项全选中该一级项下的二级项

    效果图

    JSP二级下拉框的一种简单写法 - 图1

    //数据绑定

    ids=event_classify_ids.split(“,”);
    var opinionList=${requestScope.opinion.opinion
    $(“#nature”).val(grade);
    $(“#regionId”).val(regionId);
    for (let m = 0; m for (let i = 0; i <opinionList.length; i++) {
    for (let k = 0; k < opinionList[i].children.length; k++) {
    if (opinionList[i].children[k].opinionChildId == ids[m]) {
    debugger
    $(“#asd”+ids[m]+””).attr(“checked”,”true”)
    }
    }
    }
    }
    }