답변:
if (!$("input[name='html_elements']:checked").val()) {
alert('Nothing is checked!');
}
else {
alert('One of the radio buttons is checked!');
}
.val() == ""하고 제거 할 수 있다고 생각합니다 !.
.val()체크 된 라디오 버튼이 있다면 무엇을 반환 value=""할까요? (나는 당신이 그럴 가능성이 거의 없다고 주장 할 수 있다고 생각하지만).
if ($("input[name='html_elements']:checked").val() == "")"Nothing is check"라는 경고 메시지가 표시됩니다.
나는 사용하고있다
$("input:radio[name='html_radio']").is(":checked")
라디오 그룹의 모든 항목이 선택되지 않은 경우 FALSE를 반환하고 항목이 선택되면 TRUE를 반환합니다.
다음과 같이 할 수 있습니다.
var radio_buttons = $("input[name='html_elements']");
if( radio_buttons.filter(':checked').length == 0){
// None checked
} else {
// If you need to use the result you can do so without
// another (costly) jQuery selector call:
var val = radio_buttons.val();
}
if ($("input[name='html_elements']:checked").length == 0){없습니까?
사용 .length을 참조 http://api.jquery.com/checked-selector/
if ($('input[name="html_elements"]:checked').length === 0) alert("Not checked");
else alert("Checked");
var len = $('#your_form_id input:radio:checked').length;
if (!len) {
alert("None checked");
};
alert("checked: "+ len);
이렇게 간단하게 사용하고 있습니다
HTML
<label class="radio"><input id="job1" type="radio" name="job" value="1" checked>New Job</label>
<label class="radio"><input id="job2" type="radio" name="job" value="2">Updating Job</label>
<button type="button" class="btn btn-primary" onclick="save();">Save</button>
스크립트
$('#save').on('click', function(e) {
if (job1.checked)
{
alert("New Job");
}
if (job2.checked)
{
alert("Updating Job");
}
}