|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script src="jquery-1.6.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$("input[name='love']").click(function () {
//獲得所有name為love的選中的複選框
var $Checks = $("input[name='love']:checked");
var arr = new Array();
//使用了元素的each方法
//迴圈Jquery對象裡的dom數組
$Checks.each(function (index, value) {
//alert(value);
arr[index] = value.value;
});
$("#MessageInfo").text("你選擇了"+arr.length+"個愛好,"+arr.join(","));
});
});
</script>
</head>
<body>
<input type="checkbox" name="love" value="FootBall" />足球
<input type="checkbox" name="love" value="BasketBall" />籃球
<input type="checkbox" name="love" value="VallyBall" />排球
<p id="MessageInfo"></p>
</body>
</html>
|