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

Example code about jQuery method output

零下一度
Release: 2017-06-29 13:43:45
Original
1144 people have browsed it

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>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template