复选框操作

来源:互联网 发布:阿里云ecs安装教程 编辑:程序博客网 时间:2024/05/20 08:23

1html

<thead>    <tr>        <th ><label><input type="checkbox" class="chooseAll" autocomplete="off">全选</label></th>    </tr> </thead><pre name="code" class="html"><tbody>            <tr>         <th ><input type="checkbox" class="id choose" value="" autocomplete="off"></th>     </tr>     <pre name="code" class="html"><pre name="code" class="html">     <tr>         <th ><input type="checkbox" class="id choose" value="" autocomplete="off"></th>     </tr> </tbody>



2全选/取消全选

<script>        function chooseAll(){            if($(this).is(':checked'))            {                $('.choose').prop("checked",true);            }            else            {                $('.choose').prop("checked",false);            }        }        function share(){            var ids=new Array;            $('.id:checked').each(function(){                var val=$(this).val();                ids.push(val);            });            if(ids.length > 0){                 window.location.href='www.xx.com?ids='+ids.join('|');            }else{                layer.alert('请选择XXX');            }        }        $(function(){            $('.chooseAll').click(chooseAll);            $('.choose').click(function(){                if(!$(this).is(':checked'))                {                    $('.chooseAll').prop("checked",false);                }            });            $('.share').click(share);        });    </script>


0 0
原创粉丝点击