JQuery 进入页面默认给已赋值的复选框打钩

   效果:

JQuery 进入页面默认给已赋值的复选框打钩

JQuery代码:

$("#menuTree").find("div span").click(function () {
    currmenuid = this.id;
    var currmenuname = LoadCurrMenuName();
    $('#authName').text(currmenuname);
    //默认给已赋值的菜单打钩
    var rightvalue= AutoCheck();
    var str = "";
    var strArr = [];
    for (var i = 0; i < rightvalue.length; i++) {
     str = rightvalue[i];
     strArr.push(str);
    }
    var input = $('.che');
    for (var n = 0; n < strArr.length; n++) {
     if (strArr[n] == 1) {
      input[n].checked = true;
     }
     else {
      input[n].checked = false;
     }
    }
   })

  HTML代码:

<div style="width:100%; margin:auto">
      <fieldset class="duxuan">
       <legend id="authName" style="font-size:12px;">权限管理</legend>
       <div class="duleft">
        <ul>
         <li> <input class="che" type="checkbox" name="CheckboxGroup1" value="0" id="CheckboxGroup1_1" />有效 </li>
         <li> <input class="che" type="checkbox" name="CheckboxGroup1" value="0" id="CheckboxGroup1_2" />银码 </li>
         <li> <input class="che" type="checkbox" name="CheckboxGroup1" value="0" id="CheckboxGroup1_3" />查询 </li>
         <li> <input class="che" type="checkbox" name="CheckboxGroup1" value="0" id="CheckboxGroup1_4" />新增 </li>
         <li> <input class="che" type="checkbox" name="CheckboxGroup1" value="0" id="CheckboxGroup1_5" />修改 </li>
         <li> <input class="che" type="checkbox" name="CheckboxGroup1" value="0" id="CheckboxGroup1_6" />删除 </li>
         <li> <input class="che" type="checkbox" name="CheckboxGroup1" value="0" id="CheckboxGroup1_7" />提交 </li>
         <li> <input class="che" type="checkbox" name="CheckboxGroup1" value="0" id="CheckboxGroup1_8" />统计 </li>
         <li> <input class="che" type="checkbox" name="CheckboxGroup1" value="0" id="CheckboxGroup1_9" />复核 </li>
         <li> <input class="che" type="checkbox" name="CheckboxGroup1" value="0" id="CheckboxGroup1_10" />签收 </li>
         <li> <input class="che" type="checkbox" name="CheckboxGroup1" value="0" id="CheckboxGroup1_11" />返回 </li>
         <li> <input class="che" type="checkbox" name="CheckboxGroup1" value="0" id="CheckboxGroup1_12" />导出 </li>
         <li> <input class="che" type="checkbox" name="CheckboxGroup1" value="0" id="CheckboxGroup1_13" />打印 </li>
         <li> <input class="che" type="checkbox" name="CheckboxGroup1" value="0" id="CheckboxGroup1_14" />查看 </li>
         <li> <input class="che" type="checkbox" name="CheckboxGroup1" value="0" id="CheckboxGroup1_15" />隶属角色 </li>
         <li> <input class="che" type="checkbox" name="CheckboxGroup1" value="0" id="CheckboxGroup1_16" />隶属用户 </li>
        </ul>
       </div>
       <div class="duright">
        <div class="rleft">
         <div class="rlup" id="selectAll" role="button">全选</div>
         <div class="rldown" id="resetAll" role="button">清空</div>
        </div>
        <div class="rright" id="saveAll">
         保存权限
        </div>
       </div>
      </fieldset>
     </div>

相关推荐