<h1>입력 양식 선택자2</h1>
<h3>체크박스 선택자</h3>
선호 영화 장르 : <br>
<input type="checkbox" name="genre" id="sf">SF
<input type="checkbox" name="genre" id="ani"> 애니메이션
<input type="checkbox" name="genre" id="thriller">스릴러
<br>
<input type="checkbox" name="genre" id="romentic"> 로멘틱코메디
<input type="checkbox" name="genre" id="action">액션
<script>
//onchange: 값이 변경될 때를 감지하는 이벤트 리스너
$('input:checkbox').change(checkGenre);
function checkGenre(){
console.log($(this).attr('id'));
console.log($(this).prop('checked'));
//attr()/prop()
//attr()은 id, class와 같이 속성값이 문자열일 경우 사용하고,
//prop()는 checked, disabled,required와 같이 속성값이
//true/false 로 나뉘는 속성을 확인 할때 사용한다.
if($(this).prop('checked')){
$(this).css({
width:'30px',
height:'30px'
});
} else{
$(this).css({
width:'15px',
height: '15px'
})
}
}


'JQUERY > 함수' 카테고리의 다른 글
each(), addClass(), toggleCalss() (0) | 2022.08.28 |
---|---|
select option change (0) | 2022.08.28 |
css, val, attr, mouseenter 이벤트까지. (0) | 2022.08.28 |
input의 속성값 가져오기 (0) | 2022.08.25 |
마우스 포인트 위치할때와 잃었을때 focus()/ bulr() (0) | 2022.08.25 |