[ jQuery ] radio button control > javascript&jQuery

본문 바로가기

사이트 내 전체검색

javascript&jQuery

[ jQuery ] radio button control

작성일 18-09-10 10:34

페이지 정보

작성자 웹지기 조회 2,436회 댓글 0건

본문

checked 된 radio 값

$('input:radio[name="radio_name"]:checked').val();


특정 radio 버튼 checked

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

(checked 해제는 false)

 - value 자리에 원하는 값을 세팅하면 radio_name 으로 된 버튼중 해당 값과 매칭되는 것을 찾아 checked 처리


checked 된 radio 갯수

$("input:radio[name=radio_name]:checked").length

 - jQuery 에서 radio 버튼의 존재여부 확인, 존재하는 것중에서 checked 된게 있는지를 확인 가능

 - 화면에 해당하는 radio_name으로 radio버튼이 없어도 실행된다는 점이 장점


function Sample

if($("input[name=radio_name]:radio:checked").length == 0) {

    alert("선택된 radio가 없음");

}


raido disabled (비활성화)

$("input[name=radio_name]").attr("disabled", true);

 - 활성화시키려면 false


radio가 여러개이면서 번호형식으로 이름이 된경우 반복문 사용법(Ex: radio1, radio2, radio3)

for(var i=1; i<=3; i++){

    $('input:radio[name="radio_name'+i+'"]:checked').val();

}


추천0

비추천 0

댓글목록

등록된 댓글이 없습니다.

전체 63건 2 페이지

이미지 목록

게시물 검색
Copyright © 즐거운 코딩 생활 ( funyphp ). All rights reserved.
PC 버전으로 보기