Radio 체크 박스 선택하기
https://stackoverflow.com/questions/426258/setting-checked-for-a-checkbox-with-jquery
jQuery 1.6+
Use the new .prop()
method:
$('.myCheckbox').prop('checked', true);
$('.myCheckbox').prop('checked', false);
jQuery 1.5.x and below
The .prop()
method is not available, so you need to use .attr()
.
$('.myCheckbox').attr('checked', true);
$('.myCheckbox').attr('checked', false);
Note that this is the approach used by jQuery's unit tests prior to version 1.6 and is preferable to using
$('.myCheckbox').removeAttr('checked');
since the latter will, if the box was initially checked, change the behaviour of a call to .reset()
on any form that contains it - a subtle but probably unwelcome behaviour change.
For more context, some incomplete discussion of the changes to the handling of the checked
attribute/property in the transition from 1.5.x to 1.6 can be found in the version 1.6 release notesand the Attributes vs. Properties section of the .prop()
documentation.
Any version of jQuery
If you're working with just one element, you can always just modify the HTMLInputElement
's .checked
property:
$('.myCheckbox')[0].checked = true;
$('.myCheckbox')[0].checked = false;
The benefit to using the .prop()
and .attr()
methods instead of this is that they will operate on all matched elements.
Radio 체크 박스 값 가져오기
https://stackoverflow.com/questions/596351/how-can-i-know-which-radio-button-is-selected-via-jquery
To get the value of the selected radioName
item of a form with id myForm
:
$('input[name=radioName]:checked', '#myForm').val()
Here's an example:
$('#myForm input').on('change', function() {
alert($('input[name=radioName]:checked', '#myForm').val());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form id="myForm">
<input type="radio" name="radioName" value="1" /> 1 <br />
<input type="radio" name="radioName" value="2" /> 2 <br />
<input type="radio" name="radioName" value="3" /> 3 <br />
</form>
예제> rdaio버튼 가져오기
<input name="name_of_your_radiobutton" value="YES" checked="checked">
<input name="name_of_your_radiobutton" value="NO">
$('input[name=name_of_your_radiobutton]:checked').val();
YES를 가져오겠죠.
참고: https://stackoverflow.com/questions/8622336/jquery-get-value-of-selected-radio-button
'Web > jQuery' 카테고리의 다른 글
jQuery Mobile의 뒤로 가기 오류가 생긴다면. (0) | 2018.05.25 |
---|---|
video tag 멈추게 하기 $('#vd').get(0).pause() 처리 (0) | 2017.12.21 |
jquery 에서 다른 링크 클릭 이벤트 부르기 (0) | 2017.12.16 |
jQuery <select><option value="1|TOUR"> value값에 2개 이상의 추가하기 ( 구분자 사용 ) (0) | 2017.10.18 |
jQuery를 이용한 Image 태그 src변경하기 (클릭시 로테이션) (0) | 2017.10.06 |
jQuery 태그의 name이 특정 문자가 들어간 태그 핸들링 (0) | 2017.09.13 |
[jQuery] .hide(), .show()처럼, visibility:hidden으로 설정하기 (0) | 2014.01.14 |
[jQuery] Element Properties Modify 명령 (0) | 2013.10.08 |
(로그인하지 않으셔도 가능)