zoukankan      html  css  js  c++  java
  • jQuery方法输出有几个checkbox框被选中

    每选中一个多选框,输出有多少个选中

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
        <script src="js/jquery.1.1.1.js"></script>
        <script>
             $(function () {
                 function countChecked() {
                    var n=$("#form1 input[type=checkbox]:checked").length;
                    $("div:first").html(""+n+"个checkbox被选中");
                }
                $("#form1 input[type=checkbox]").click(countChecked);//每选一个框调用一次函数,不带括号
             })
        </script>
    </head>
    <body>
        <form action="" id="form1">
            <input type="checkbox" name="newsletter" checked="checked" value="test1" />test1
            <input type="checkbox" name="newsletter" value="test2" />test2
            <input type="checkbox" name="newsletter" value="test3" />test3
            <input type="checkbox" name="newsletter" checked="checked" value="test4" />test4
            <input type="checkbox" name="newsletter" value="test5" />test5
            <div></div>
        </form>
    </body>
    </html>
  • 相关阅读:
    JavaScript
    CSS
    HTML5&CSS
    I2C mux和复杂拓扑
    如何实例化I2C设备
    SMBus 协议
    I2C 协议
    I2C和SMBus简介
    ubuntu20.04系统下更新Raspberry Pi4的DTB
    通过configfs配置的Linux USB gadget
  • 原文地址:https://www.cnblogs.com/lwj820876312/p/7090213.html
Copyright © 2011-2022 走看看