JQuery 中 实现复选框全选/全不选/反选功能 案例

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="UTF-8">
    <script src="jq183.js"></script>//引入JQuery代码库
</head>
<body>
<input type="button" value="全选" id="all">
<input type="button" value="全不选" id="unall">
<input type="button" value="反选" id="un">
<hr>
<input type="checkbox" value=""> HTML  <br>
<input type="checkbox" value=""> Javascript <br>
<input type="checkbox" value=""> PHP <br>
<input type="checkbox" value=""> Python <br>
<input type="checkbox" value=""> Java <br>
<input type="checkbox" value=""> C/C++ <br>
</body>
<script>
    $.fn.extend({
        //全选 将所有的 CheckBox的checked 属性 都为true
        all:function(){
            this.attr('checked',true)
        },
        //全不选 将所有的checked 属性值都变成false
        unall:function(){
            this.attr('checked',false)
        },
        //反选 将所有的checked属性值取反
        un:function(){
            for(var i=0;i<this.length;i++){
                this[i].checked=!this[i].checked;
            }
        }
    })
    $('#all').click(function(){
        $(':checkbox').all();
    })
    $('#unall').click(function(){
        $(':checkbox').unall();
    })
    $('#un').click(function(){
        $(':checkbox').each(function(){
            //判断并取反
            if(this.checked==true){
                this.checked=false;
            }else{
                this.checked=true;
            }
            //直接取反
           // this.checked=!this.checked;
        })
    })
</script>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是使用 jQuery 实现九九乘法表、全选/全不选反选功能和轮播图的示例代码: 1. 九九乘法表: ```html <!DOCTYPE html> <html> <head> <title>九九乘法表</title> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> </head> <body> <table id="multiplication-table"> <tbody></tbody> </table> <script> $(document).ready(function() { var table = $('#multiplication-table tbody'); for (var i = 1; i <= 9; i++) { var row = $('<tr></tr>'); for (var j = 1; j <= 9; j++) { var cell = $('<td></td>').text(i + ' × ' + j + ' = ' + (i * j)); row.append(cell); } table.append(row); } }); </script> </body> </html> ``` 2. 全选/全不选反选功能: ```html <!DOCTYPE html> <html> <head> <title>全选/全不选反选功能</title> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> </head> <body> <label><input type="checkbox" id="check-all"> 全选/全不选</label><br> <input type="checkbox" class="checkbox-item"> Item 1<br> <input type="checkbox" class="checkbox-item"> Item 2<br> <input type="checkbox" class="checkbox-item"> Item 3<br> <button id="invert-selection">反选</button> <script> $(document).ready(function() { $('#check-all').change(function() { $('.checkbox-item').prop('checked', $(this).prop('checked')); }); $('#invert-selection').click(function() { $('.checkbox-item').each(function() { $(this).prop('checked', !$(this).prop('checked')); }); }); }); </script> </body> </html> ``` 3. 轮播图: ```html <!DOCTYPE html> <html> <head> <title>轮播图</title> <style> .slider { width: 300px; height: 200px; overflow: hidden; position: relative; } .slider img { width: 100%; height: 100%; position: absolute; transition: opacity 1s ease-in-out; } </style> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> </head> <body> <div class="slider"> <img src="image1.jpg" alt="Image 1"> <img src="image2.jpg" alt="Image 2"> <img src="image3.jpg" alt="Image 3"> </div> <script> $(document).ready(function() { var slider = $('.slider'); var images = slider.find('img'); var currentIndex = 0; function showImage(index) { images.css('opacity', 0); $(images[index]).css('opacity', 1); } function nextImage() { currentIndex = (currentIndex + 1) % images.length; showImage(currentIndex); } setInterval(nextImage, 2000); }); </script> </body> </html> ``` 请注意替换示例的图片路径和文件名,确保图片可以正确加载。希望能对你有所帮助!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值