체크박스 전체 선택 /해제
<html>
<head>
<title>title</title>
<script type = "text/javascript" src= "jquery-1.4.2.min.js" ></script>
</head>
<body>
<input type="button" id ="chkall" value="select" >
<input type="checkbox" id="chkAll" />
<input type="checkbox" name="chk" id="checkbox1" value="1" />
<input type="checkbox" name="chk" id="checkbox2" value="2" />
<input type="checkbox" name="chk" id="checkbox3" value="3" />
<input type="checkbox" name="chk" id="checkbox4" value="4" />
<input type="checkbox" name="chk" id="checkbox5" value="5" />
<input type="checkbox" name="chk" id="checkbox6" value="6" />
<script type="text/javascript">
$(function(){
$("#chkAll").click(function()
{
$bChk = $(this).is(':checked');
if(this.checked){
$(":checkbox").attr("checked", $bChk);
}
else{
$(":checkbox").attr("checked","");
}
});
});
</script>
</body>
</html>
<html>
<head>
<title>title</title>
<script type = "text/javascript" src= "jquery-1.4.2.min.js" ></script>
</head>
<body>
<input type="button" id ="selall" value="select" >
<input type="checkbox" id="chkAll" onclick="chk_all('chkAll');" />
<input type="checkbox" name="chk" id="checkbox1" value="1" />
<input type="checkbox" name="chk" id="checkbox2" value="2" />
<input type="checkbox" name="chk" id="checkbox3" value="3" />
<input type="checkbox" name="chk" id="checkbox4" value="4" />
<input type="checkbox" name="chk" id="checkbox5" value="5" />
<input type="checkbox" name="chk" id="checkbox6" value="6" />
<script type="text/javascript">
function chk_all(xVal){
var checkflag = "false";
$bChk = $("#"+xVal).is(':checked');
if(checkflag == "false"){
$(":checkbox").attr("checked", $bChk);
}
else{
$(":checkbox").attr("checked","");
}
}
</script>
</body>
</html>
[출처] http://99ani.blog.me/60104668199
'프로그램&DB > jQuery&JS' 카테고리의 다른 글
JQuery 사용해보기 - 엘리먼트 다루기 by naearu님 (0) | 2012.01.05 |
---|---|
jQuery.classBehaviours.handlers.layerPopUp 레이어 팝업 (0) | 2011.12.12 |
[jquery] checkbox 다루기 (0) | 2011.08.29 |
[jQuery] jQuery form 전송 (0) | 2011.08.29 |
[jQuery] radio , select 에서 value 값 가져오기 (0) | 2011.08.29 |