每选中一个多选框,输出有多少个选中
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <script src="js/jquery.1.1.1.js?1.1.11"> </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>
以上就是关于jQuery方法输出的实例代码的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号