2-05 3,103 views
"html代码"
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<script src="http://lib.sinaapp.com/js/jquery/1.9.1/jquery-1.9.1.min.js"></script>
<style type="text/css">
*{
padding: 0;
margin: 0;
}
.box{
margin: 200px auto;
width: 200px;
height: 200px;
overflow: hidden;
display: block;
}
</style>
</head>
<body>
<div class="box">
1.<input type="checkbox">
2.<input type="checkbox">
3.<input type="checkbox">
4.<input type="checkbox">
<input type="button" value="按钮" id="btn">
</div>
</body>
</html>
"Jquery代码"
<script type="text/javascript">
$(function(){
$('#btn').click(function() {
//选择所有的checkbox
$('.box').find('input:checkbox').each(function() {
//方法一,原生对象
if ($(this)[0].checked) {
alert(1)
};
//方法二
if ($(this).is(':checked')) {
alert(1)
};
});
});
})
</script>