兄弟文章: http://blog.csdn.net/libin_1/article/details/50734967
方法一:
if ($("#checkbox-id").get(0).checked) {
// do something
}
方法二:
if($(‘#checkbox-id‘).is(‘:checked‘)) {
// do something
}
方法三:
if ($(‘#checkbox-id‘).attr(‘checked‘)) {
// do something
}
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<script type="text/javascript" src="js/jquery-2.2.2.min.js"></script>
<title>Document</title>
<script type="text/javascript">
$(function() {
$("#button").click(function() {
var h = $("input[type=‘checkbox‘]").length;
var s = ‘‘;
for (var i = 0; i < h; i++) {
if ($("input[type=‘checkbox‘]").eq(i).is(‘:checked‘)) {
s += $("input[type=‘checkbox‘]").get(i).value;
}
}
alert(s);
})
})
</script>
<script type="text/javascript">
$(function() {
$("#button1").click(function() {
var h = $("input[type=‘radio‘]").length;
var s = ‘‘;
for (var i = 0; i < h; i++) {
if ($("input[type=‘radio‘]").eq(i).is(‘:checked‘)) {
s += $("input[type=‘radio‘]").eq(i).val();
}
}
alert(s);
})
})
</script>
</head>
<body>
<input type="checkbox" name="box" id="box1" value="跳水" checked="checked" />跳水
<input type="checkbox" name="box" id="box2" value="跑步" />跑步
<input type="checkbox" name="box" id="box3" value="听音乐" />听音乐
<input type="button" name="button" id="button" value="提交" />
<br />
<input type="radio" name="box" id="box1" value="跳水" checked="checked" />跳水
<input type="radio" name="box" id="box2" value="跑步" />跑步
<input type="radio" name="box" id="box3" value="听音乐" />听音乐
<input type="button" name="button" id="button1" value="提交" />
</body>
</html>
时间: 2024-10-08 05:09:56