JS - 全部选择、取消全部选择 - 2

<script>
function SelectAll() {
    var operate = $(".member_tab tr");
    var bool = $("#allchecked").attr('checked');
    operate.each(function () {
        $(this).find('input[type=checkbox]').attr("checked", bool ? true : false);
    });
}
</script>
<table class="member_tab" width="100%">
<!--{if $peoplestr}-->
    <tr>
        <th style=" text-align:center;" width="4%">
            <input name="xuan" type="checkbox" id="allchecked" onclick="SelectAll()" />
        </th>
        <th><span>|</span>用户名</th>
        <th><span>|</span>姓名</th>
        <th><span>|</span>手机号</th>
        <th><span>|</span>邮箱</th>
    </tr>
    <!--{foreach item=people from=$peoplestr name=foo}-->
    <tr>
        <td style="text-align:center;">
        <!--{if $people.uuid neq $uuid}-->
        <input name="delte" type="checkbox" value="<!--{$people.id}-->" />
        <!--{/if}-->
        </td>
        <td><!--{$people.username}--></td>
        <td><!--{$people.name}--></td>
        <td><!--{$people.move}--></td>
        <td><!--{$people.email}--></td>
    </tr>
    <!--{/foreach}-->
<!--{/if}-->
</table>

高级版

<script>
    //全选
    function SelectAll() {
        var operate = $(".member_tab tr");
        var bool = $("#allchecked").is(':checked');
        operate.each(function () {
            if(!$(this).find('input[type=checkbox]').is(":disabled"))
            {
                $(this).find('input[type=checkbox]').attr("checked", bool ? true : false);
            }
        });
    }
</script>
<table class="member_tab" width="100%">
    <!--{if $peoplestr}-->
    <tr>
        <th style=" text-align:center;" width="4%">
            <input name="xuan" type="checkbox" id="allchecked" onclick="SelectAll()" />
        </th>
        <th><span>|</span>用户名</th>
        <th><span>|</span>姓名</th>
        <th><span>|</span>手机号</th>
        <th><span>|</span>邮箱</th>
    </tr>
    <!--{foreach item=people from=$peoplestr name=foo}-->
    <tr>
        <td style="text-align:center;">
            <!--{if $people.uuid neq $uuid}-->
            <input name="delte" type="checkbox" value="<!--{$people.uuid}-->" />
            <!--{else}-->
            <input name="delte" type="checkbox" value="<!--{$people.uuid}-->" onclick="return false;" disabled="disabled"/>
            <!--{/if}-->
        </td>
        <td>
            <!--{if $people.uuid neq $uuid}-->
            <!--{$people.username}-->
            <!--{else}-->
            <b><!--{$people.username}--></b>(组织建立者)
            <!--{/if}-->
        </td>
        <td><!--{$people.name}--></td>
        <td><!--{$people.move}--></td>
        <td><!--{$people.email}--></td>
    </tr>
    <!--{/foreach}-->
    <!--{/if}-->
</table>
返回文章列表 打赏
本页链接的二维码
打赏二维码
期待你的评论

8 条评论
  1. Ihoey 白银   Ihoey  

    好奇的问一下,那个用户头像怎么设置,为什么我的头像一直是这样的呢

    1. 小尾巴 王者   小尾巴   博主
      @ Ihoey

      需要去 avatar 设置一下

  2. themebetter 青铜   themebetter  

    总结的很不错哟,值得学习。

    1. 小尾巴 王者   小尾巴   博主
      @ themebetter

      谢谢夸奖 ๑乛◡乛๑

  3. c0smxsec 大师   c0smxsec  

    @(真棒)收藏

    1. 小尾巴 王者   小尾巴   博主
      @ c0smxsec

      棒棒哒 ๑乛◡乛๑

  4. 芝麻 钻石   芝麻  

    学习了~

    1. 小尾巴 王者   小尾巴   博主
      @ 芝麻

      好好学习,天天向上 ๑乛◡乛๑