點擊tr中的全選使tr中的全部checkbox全選上

頁面的代碼以下: this

<table cellpadding="0" cellspacing="0" id="viewTable" class="tablesorter">
    <thead>
     <tr>
     <th  width="10%"><fmt:message key="projectmember.department.title"/></th>
     <th  width="85%"><fmt:message key="projectmember.userid.title"/></th>
     <th  width="5%"><fmt:message key="operation"/></th>
     </tr>
    </thead>
    <tbody>
     <c:forEach items="${departments}" var="current"  varStatus="i"> 
      <c:choose>
       <c:when test="${(i.count) % 2 == 0}">
           <c:set var="rowclass" value="rowtwo"/>
       </c:when>
       <c:otherwise>
           <c:set var="rowclass" value="rowone"/>
       </c:otherwise>
      </c:choose>
     <tr class="${rowclass}">
      <td>
       ${current.name}
      &nbsp;
      </td>
      <td id="one${current.id}">      
         <c:forEach items="${current.users}" var="user"  varStatus="j">
          <form:checkbox path="userName" value="${user.id}" />${user.cname}&nbsp;
         </c:forEach>                 
      </td>
      <td>
      <input type="button" onclick="test('${current.id}');" value="全選"/>
      </td>
     </tr>
     </c:forEach>
    </tbody>
   </table> spa

一種方法是<td>
      <input type="button" onclick="test('${current.id}');" value="全選"/>
      </td> orm

function test(i) { 
  var str="one"+i;
  $("#"+str+" :"+'input[type=checkbox]').attr("checked",true);
         } ci

另外一種方法是<td>
      <input type="checkbox" onclick="test('${current.id}',this);" /> 全選
      </td> input

fufunction test(i,checkbox) { 
  var str="one"+i;
  $("#"+str+" :"+'input[type=checkbox]').prop('checked', $(checkbox).prop('checked'));
         } it

相關文章
相關標籤/搜索