체크박스 선택여부, checked처리 라디오버튼 선택과 해제 > script

본문 바로가기
사이트 내 전체검색

script

체크박스 선택여부, checked처리 라디오버튼 선택과 해제

페이지 정보

작성자 서방님 댓글 0건 조회 190회 작성일 13-09-26 18:01

본문

 

1. checked 여부 확인

1
2
$("input:checkbox[id='ID']").is(":checked") == true false  /* by ID */
$("input:checkbox[name="NAME"]).is(":checked") == true : falce /* by NAME */


2. checked/unchecked 처리

1
2
$("input:checkbox[id='ID']").attr("checked"true); /* by ID */
$("input:checkbox[name='NAME']").attr("checked"false); /* by NAME */


3. 특정 라디오버튼 선택 / 모든 라디오버튼 선택해제

1
2
$("input:radio[name='NAME']:radio[value='VALUE']").attr("checked",true);
$("input:radio[name='NAME']").removeAttr("checked");

 


전체선택 체크박스를 선택하면 그 아래의 모든 체크박스를 선택해주는 것을 만들어보자.

 

1
2
3
4
5
<label><input type='checkbox' id='check_all' class='input_check' /> <b>전체선택</b></label>
<ul class='select_subject'>
<label><input type='checkbox' class='input_check' name='class[1]' value='1' /> <b>1</b></label>
<label><input type='checkbox' class='input_check' name='class[2]' value='2' /> <b>2</b></label>
</ul>

 

<input type="checkbox" id="check_all" class="input_check" style="margin: 0px; padding: 0px; border-width: 0px;" /> 전체선택

  • <label style="margin: 0px; padding: 0px;"><input type="checkbox" class="input_check" name="class[1]" value="1" style="margin: 0px; padding: 0px; border-width: 0px;" /> <b style="margin: 0px; padding: 0px;">1</b></label> <label style="margin: 0px; padding: 0px;"><input type="checkbox" class="input_check" name="class[2]" value="2" style="margin: 0px; padding: 0px; border-width: 0px;" /> <b style="margin: 0px; padding: 0px;">2</b></label>

 

이런식으로 html이 있고, javascript 부분은 

 

1
2
3
4
5
6
7
$(function(){
    $("#check_all").click(function(){
        var chk = $(this).is(":checked");//.attr('checked');
        if(chk) $(".select_subject input").attr('checked'true);
        else  $(".select_subject input").attr('checked'false);
    });
});

 

같이 해주면 된다.

 

 

댓글목록

등록된 댓글이 없습니다.

Total 846건 8 페이지
게시물 검색

회원로그인

접속자집계

오늘
78
어제
84
최대
1,347
전체
154,449
Latest Crypto Fear & Greed Index

그누보드5
Copyright © 서방님.kr All rights reserved.