jquery的each()
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<meta charset="utf-8" />
<script src="jquery-3.3.1.js"></script>
<script>
$(function () {
var cks = $('div input:checked');
cks.each(function (index,ele) {
alert($(ele).val());
})
})
</script>
</head>
<body>
<div>
<input type="checkbox" name="name" value="1" checked="checked"/>吃饭
<input type="checkbox" name="name" value="2" checked="checked"/>睡觉
<input type="checkbox" name="name" value="3" checked="checked"/>打乒乓球
<input type="checkbox" name="name" value="4" />打篮球
<input type="checkbox" name="name" value="5" />踢足球
<input type="checkbox" name="name" value="6" />打豆豆
</div>
</body>
</html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<meta charset="utf-8" />
<script src="jquery-3.3.1.js"></script>
<script>
$(function () {
var cks = $('div input:checked');
cks.each(function (index,ele) {
alert($(ele).val());
})
})
</script>
</head>
<body>
<div>
<input type="checkbox" name="name" value="1" checked="checked"/>吃饭
<input type="checkbox" name="name" value="2" checked="checked"/>睡觉
<input type="checkbox" name="name" value="3" checked="checked"/>打乒乓球
<input type="checkbox" name="name" value="4" />打篮球
<input type="checkbox" name="name" value="5" />踢足球
<input type="checkbox" name="name" value="6" />打豆豆
</div>
</body>
</html>