All <input id="check_all" onclick="checkedAll(this)" type="checkbox">
check1 <input id="check1" onclick="checkboxOne()" type="checkbox">
check2 <input id="check2" onclick="checkboxOne()" type="checkbox">
check3 <input id="check3" onclick="checkboxOne()" type="checkbox">
check4 <input id="check4" onclick="checkboxOne()" type="checkbox">
<script type="text/javascript">
//<![CDATA[
	var AllObj = document.getElementById("check_all");
	var checkboxArr = new Array("check1","check2","check3","check4");
	function checkbox_checked(bool)
	{
		for(var n in checkboxArr) document.getElementById(checkboxArr[n]).checked = bool;
	}
	function checkedAll(obj) {
		var bool = obj.checked;return checkbox_checked(bool);
	}
	function checkboxOne()
	{
		var cnt=0;
		for(var n in checkboxArr) if(document.getElementById(checkboxArr[n]).checked === true) cnt++;
		if(cnt == checkboxArr.length) AllObj.checked = true;
		else AllObj.checked = false;
	}
//]]>
</script>


'Language > Javascript' 카테고리의 다른 글

슬라이딩  (0) 2008.11.25
lightbox2  (1) 2008.06.18

+ Recent posts