[ jQuery ] radio button control > javascript&jQuery

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

javascript&jQuery

[ jQuery ] radio button control

작성자 웹지기
작성일 18-09-10 10:34 | 조회 4,393 | 댓글 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

댓글목록 0

등록된 댓글이 없습니다.

javascript&jQuery 목록

Total 63
게시물 검색

회원로그인

접속자집계

오늘
1,599
어제
31,923
최대
61,067
전체
18,311,523

그누보드5
Copyright © www.funyphp.com. All rights reserved.