My Name is Kay....

DIY , 먹방 , 개발 , 육아 , 여행 좋아합니다.
AdBlock 사용시 화면이 정상적으로 노출되지 않습니다.
포스팅 관련 문의 및 개발 문의는 Email : wkzkfmxksi@gmail.com

추가 포스팅이 이뤄지지 않는 블로그입니다. 문의는 wkzkfmxksi@gmail.com 으로 연락주세요.
A to Z
2013.05.06 10:46

CheckBox 값 읽어오기

kay
조회 수 25268 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄


기존에 만들어둔 샘플들 보다 유용하고 간단한것같아서 퍼왔습니다. 

공유해주신 namkyu 님께 감사드립니다.


체크 박스 관련 샘플  (원문 : http://lng1982.tistory.com/80 )


<!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>


?

List of Articles
번호 분류 제목 글쓴이 날짜 조회 수
54 UI woothemes FlexSlider - 슬라이더 file kay 2014.09.16 286628
53 PlugIn jQuery Plugin For Auto Resizing iFrame - iFrame Resizer file kay 2014.03.10 105535
52 UI SelectBox Option 값 초기화 및 수정 삭제 kay 2013.03.02 36660
51 PlugIn fancyBox - 레이어팝업 (추천) kay 2013.04.16 32412
50 etc 에러 리포팅 , Ajax 디버깅 ( JS , ASP ) - 오류메시지 확인하기 kay 2013.03.08 30612
49 UI animate - 각종 애니메이션 효과 kay 2013.04.11 26329
» A to Z CheckBox 값 읽어오기 kay 2013.05.06 25268
47 etc Table에 동적 Tr 추가/삭제 하기 kay 2014.02.09 21275
46 PlugIn jquery-syaku.rolling 상하좌우 롤링 ( 자동롤링 , 버튼 ) 10 file kay 2014.02.09 20160
45 UI 스크롤 탑 컨트롤 - scrolltop control kay 2013.05.29 18965
44 PlugIn makisu - 메뉴 접기(?) kay 2013.04.16 18446
43 PlugIn tiptip - 툴팁 kay 2013.04.14 17886
42 PlugIn jQuery Org Chart - 조직도 그리기 file kay 2014.09.01 16611
41 PlugIn 자동 롤링 배너 Jquery 2 file kay 2013.08.07 13881
40 PlugIn Star Rating Plugin - jQuery 별점 주기 2 file kay 2014.05.01 13221
39 PlugIn Smooth Scroll - 스크롤 이동 ( 속도 , 위치 ) 2 file kay 2013.04.06 12678
38 PlugIn poshytip - 툴팁 kay 2013.04.15 11803
37 UI 동적으로 추가된 객체에 datepicker() 적용하기 kay 2013.11.06 10135
36 etc 한글/영어 byte 체크해서 자르기 1 kay 2013.11.30 9702
35 UI select Box option ( 초기화,추가,삭제 ) kay 2013.04.03 9533
Board Pagination Prev 1 2 3 Next
/ 3