获取 checkbox 的选中个数(转)


获取 checkbox的 选中个数可以直接使用如下jquery语法:

1 $("input[type='checkbox']:checked").length;

示例如下:

  1. 创建Html代码及css样式 

    <div> 
        <input type="checkbox" name="fruit"> apple
        <input type="checkbox" name="fruit"> orange
        <input type="checkbox" name="fruit"> banana
        <input type="checkbox" name="fruit"> watermelon
        <input type="button" value="I like these fruit!">
    </div>
    div{width:500px;padding:20px;border:4px solid #ebcbbe;}
    input{margin:10px 5px;}

     

  2. jquery代码

    $(function(){
        $("input[type='button']").click(function() {
            alert($("input[type='checkbox']:checked").length);
        });
    })

     

  3. 效果


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM