jQuery prop全选

来源:互联网 发布:游戏抽奖软件 编辑:程序博客网 时间:2024/05/20 00:13

jQuery prop全选:

<!DOCTYPE html><html lang="en"><head>    <meta charset="utf-8">    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">    <meta name="description" content="">    <meta name="author" content="">    <link rel="icon" href="favicon.ico">    <title></title>    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script></head><body><input type="checkbox" id="all"> 全选<div>    <input type="checkbox"> 类别1    <input type="checkbox"> 类别2    <input type="checkbox"> 类别3    <input type="checkbox"> 类别4</div><script>    $(function () {        $('#all').click(function(){            $(this).siblings('div').find('input[type=checkbox]').prop('checked',$(this).prop('checked'));        })    })</script></body></html>