Home >Web Front-end >JS Tutorial >Example code about jQuery method output

Example code about jQuery method output

零下一度
零下一度Original
2017-06-29 13:43:451145browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn