Each time a multi-select box is selected, output how many are selected
<!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>
The above is the detailed content of Example code about jQuery method output. For more information, please follow other related articles on the PHP Chinese website!