码迷,mamicode.com
首页 > 其他好文 > 详细

全选、反选

时间:2017-06-02 22:08:33      阅读:248      评论:0      收藏:0      [点我收藏+]

标签:ids   source   type   var   javascrip   enter   sources   cli   style   

           <tr  bgcolor="#FFFFFF">
                      <td width="18%" height="30" align="center">资源名称</td>
                      <td width="82%" colspan="3">
                          <input type="checkbox" id="all">全选&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                          <input type="checkbox" id="reverse">反选
                      </td>
                    </tr>
                    <tr  bgcolor="#FFFFFF">
                      <td width="18%" height="30" align="center">&nbsp;</td>
                      <td width="82%" colspan="3">
                          <c:if test="${resources != null}">
                              <c:forEach items="${resources}" var="resource">
                                  <c:forEach items="${role.resources}" var="r">
                                      <c:if test="${r.uuid == resource.uuid}">
                                          <input type="checkbox" name="resourceUuids" value="${resource.uuid}" checked>${resource.name}
                                          <c:set value="${r.uuid}" var="uid"/>
                                      </c:if>
                                  </c:forEach>
                                  <c:if test="${uid != resource.uuid}">
                                      <input type="checkbox" name="resourceUuids" value="${resource.uuid}">${resource.name}
                                  </c:if>
                              </c:forEach>
                          </c:if>
                      </td>
                    </tr>
<script type="text/javascript">
    $(function () {
        //全选
        $("#all").click(function () {
            var flag = $(this).attr("checked");
            $("[name=resourceUuids]").attr("checked",flag == "checked");

        });
        //反选
        $("#reverse").click(function () {
            $("[name=resourceUuids]").each(function () {
                var flag = $(this).attr("checked");
                $(this).attr("checked",!(flag == "checked"));
            })
            var Flag = true;
            $("[name=resourceUuids]").each(function () {
                var flag = $(this).attr("checked") == "checked";
                Flag = Flag && flag;
            })
            $("#all").attr("checked",Flag);

        });
        //绑定组件
        $("[name=resourceUuids]").click(function () {
            var Flag = true;
            $("[name=resourceUuids]").each(function () {
                var flag = $(this).attr("checked") == "checked";
                Flag = Flag && flag;
            })
            $("#all").attr("checked",Flag);
        });

    });
</script>

全选、反选

标签:ids   source   type   var   javascrip   enter   sources   cli   style   

原文地址:http://www.cnblogs.com/xuweiweiailixing/p/6935082.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!