 |
|
|  |
jquery checkbox Àüü ¼±ÅÃ, Àüü ÇØÁ¦, üũ °ª ÃßÃâ |
|
|
 |
9³â Àü |
üũ ¹Ú½º Àüü ¼®ÅÃ
üũ ¹Ú½º Àüü ÇØÁ¦
üũ µÇ¾î ÀÖ´Â °ª ÃßÃâ
¼¹ö¿¡¼ ¹Þ¾Æ¿Â µ¥ÀÌÅÍ Ã¼Å©Çϱâ (ÄÞ¸¶·Î ¹Þ¾Æ¿Â °æ¿ì)
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
// üũ ¹Ú½º ¸ðµÎ üũ
$("#checkAll").click(function() {
$("input[name=box]:checkbox").each(function() {
$(this).attr("checked", true);
});
});
// üũ ¹Ú½º ¸ðµÎ ÇØÁ¦
$("#uncheckAll").click(function() {
$("input[name=box]:checkbox").each(function() {
$(this).attr("checked", false);
});
});
// üũ µÇ¾î ÀÖ´Â °ª ÃßÃâ
$("#getCheckedAll").click(function() {
$("input[name=box]:checked").each(function() {
var test = $(this).val();
console.log(test);
});
});
// ¼¹ö¿¡¼ ¹Þ¾Æ¿Â µ¥ÀÌÅÍ Ã¼Å©Çϱâ (ÄÞ¸¶·Î ¹Þ¾Æ¿Â °æ¿ì)
$("#updateChecked").click(function() {
var splitCode = $("#splitCode").val().split(",");
for (var idx in splitCode) {
$("input[name=box][value=" + splitCode[idx] + "]").attr("checked", true);
}
});
// test case
test1();
});
function test1() {
console.log("################################################");
console.log("## test1 START");
console.log("################################################");
var cnt = $("input:checkbox").size();
console.log("checkboxSize=" + cnt);
$("input[name=box]:checkbox").each(function() {
var checkboxValue = $(this).val();
console.log("checkboxValue=" + checkboxValue);
});
console.log("----------------------------------------------");
$("#checkboxArea").children().each(function() {
var checkboxValue = $(this).children(":checkbox").val();
var text = $(this).children().eq(1).text();
console.log(text + "=" + checkboxValue);
});
}
</script>
</head>
<body>
<div id="checkboxArea">
<li><input type="checkbox" name="box" value="A" /><label>1¹ø° checkbox</label></li>
<li><input type="checkbox" name="box" value="B" /><label>2¹ø° checkbox</label></li>
<li><input type="checkbox" name="box" value="C" /><label>3¹ø° checkbox</label></li>
<li><input type="checkbox" name="box" value="D" /><label>4¹ø° checkbox</label></li>
</div>
<br/><br/>
<div id="buttonGroups">
<input type="button" id="checkAll" value="check all" />
<input type="button" id="uncheckAll" value="uncheck all" />
<input type="button" id="getCheckedAll" value="get checked all" />
<input type="button" id="updateChecked" value="updateChecked" />
</div>
<input type="hidden" id="splitCode" name="splitCode" value="A,C,D" />
</body>
</html> |
|
̵̧ : 438 |
̵̧
¸ñ·Ï
|
|
|  |
|