<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<script src="JS/jquery-1.7.min.js"></script>
<script type="text/javascript">
$(function () {
$("input[name=names]").click(function () {
var arry = new array();
$("input[name=names]:check").each(function (key, value) {
arry[key] = $(value).val();
});
$("#msginfo").text = "共选中" + arry.length + "项:" + arry.join(",");
});
});
</script>
</head>
<body>
<input type="checkbox" name="names" value="lily"/>lily
<input type="checkbox" name="names" value="tom" />tom
<input type="checkbox" name="names" value="clack" />clack
<input type="checkbox" name="names" value="jick" />jick
<p id="msginfo"></p>
</body>
</html>
这样居然敢说语法有问题,不但语法,关键词都写错了,简直错误百出...我都怀疑你是不是没学过jquery?我算是闲着没事给你写一下,自己对比一下吧
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> <script src="http://code.jquery.com/jquery-2.0.3.min.js"></script> <script type="text/javascript"> $(function () { $("input[name=names]").click(function () { var arry = new Array(); $("input[name=names]:checked").each(function (key, value) { arry.push($(value).val()); }); $("#msginfo").text("共选中" + arry.length + "项:" + arry.join(",")); }); }); </script> </head> <body> <input type="checkbox" name="names" value="lily"/>lily <input type="checkbox" name="names" value="tom" />tom <input type="checkbox" name="names" value="clack" />clack <input type="checkbox" name="names" value="jick" />jick <p id="msginfo">3</p> </body> </html>
感谢ing,我是初学者嘿嘿
@上官瑾文: 好好看一下吧,或者买一本锋利的jquery看看吧
http://www.cnblogs.com/wang7/archive/2012/10/11/2720444.html
http://www.cnblogs.com/bienfantaisie/archive/2010/03/19/1689954.html