前端——》jsp全选框的勾选与取消

<table >
  <tbody id="mail_tbody_${param.prefix}">
  <tr align="center" id="mail_th">
    <c:if test="${param.mode!='view'}">
      <th width="10px">
          <%--全选框--%>
        <input type="checkbox" id="checkALLContent" name="checkALLContent"
               onclick="selectAllmail_${param.prefix}(this)">
        <input type="hidden" id="cust_custid" value="">
      </th>
    </c:if>
    <th width="100px">联系人</th>
    <th width="140px">职位</th>
    <th width="150px">邮箱</th>
  </tr>
  <tr id="mail_tr_clone" style="display: none">
    <c:if test="${param.mode!='view'}">
      <%--单选框--%>
      <td>&nbsp;<input type="checkbox" id="cloneCheckbox" name="checkbox_mail_objid"
                       onclick="contactKeychange_${param.prefix}(this)"></td>
    </c:if>
    <td id="name">2</td>
    <td id="job">3</td>
    <td id="mail">4</td>
  </tr>
  </tbody>
</table>
<%-----------------------------------以上为jsp页面(直接从项目复制粘贴的),页面中的其他元素如${param.prefix}请忽略。以下为juqery方法-----------------------------------------------%>
function contactKeychange_${param.prefix}(data) {
  if (data.name != "" && data.name != undefined) {
    var allCheckId = "checkALLContent";
    /*设置全选框是否勾选,如果勾选的选项的长度等于总长度则勾选*/
    if (($('input[name="' + data.name + '"]:checked').length != 0) && ($('input[name="' + data.name + '"]:checked').length == $('input[name="' + data.name + '"]').length)) {
      document.getElementById(allCheckId).checked = true;
    } else {
      document.getElementById(allCheckId).checked = false;
    }
  }
}

猜你喜欢

转载自blog.csdn.net/nienianzhi1744/article/details/86690653