2009-08-26 10 views
2

여러 라디오 버튼 그룹이있는 긴 형식으로 작업하고 있습니다.jQuery 모든 라디오 버튼 그룹 선택

하단에는 라디오 버튼 "No All"이 있습니다. 그것이 선택되면 모든 "N"라디오 버튼이 선택되도록 만들고 싶습니다. 그러나 그것을 작동시키지 못합니다.

jQuery를 : 다음 코드의 간략화 된 버전이다

$(document).ready(function(){ 
//initially hide the Remove All Questions 
$("div.#removeAllquest").hide(); 

//////////// Show Remove All Questions if radio button selected 
$("input.#RemoveAll").click(function() { 
    if ($(this).is(':checked')) 
    $("input:radio [class*='radioR']").attr("checked",true); 
    else 
$("input:radio [class*='radioR']").attr("checked",false); 
}); 

는});

형태 : 내가 잘못

<table> 
    <tr> 
    <td>Y<input type="radio" name="row1" value="row1col1" class="q123col1"></td> 
    <td>N<input type="radio" name="row1" class="radioR" value="row1col2"></td> 
    <td>M<input type="radio" name="row1" value="row1col3" class="q123col3"></td> 
    </tr> 
    <tr> 
    <td>Y<input type="radio" name="row2" value="row2col1" class="q123col1"></td> 
    <td>N<input type="radio" name="row2" class="radioR" value="row2col2"></td> 
    <td>M<input type="radio" name="row2" value="row2col3" class="q123col3"></td> 
    </tr> 
    <tr> 
    <td>Y<input type="radio" name="row3" value="row3col1" class="q123col1"></td> 
    <td>N<input type="radio" name="row3" class="radioR" value="row3col2"></td> 
    <td>M<input type="radio" name="row3" value="row3col3" class="q123col3"></td> 
    </tr> 
    <tr> 
    <td colspan="2">No All </td> 
    <td> 
     <input name="RemoveAll" id="RemoveAll" type="radio" value="Y"> 
    </td> 
    </tr> 
</table> 

을 뭐하는 거지?

답변

11

두 가지 모두 작동해야합니다. 첫 번째로 나는 자신의 스타일을 유지하려고 노력했습니다. 두 번째로 나는 스타일을 조금 바꿨다. 샘플을 확인한 후에는 샘플을 선택 취소 할 방법이 없습니다.

$("input.#RemoveAll").click(function() { 
    if ($(this).is(':checked')) 
     $("input:radio.radioR").attr("checked", "checked"); 
    else 
     $("input:radio.radioR").removeAttr("checked"); 
}); 

$("#RemoveAll").click(function() { 
    if ($(this).is(':checked')) 
     $(".radioR").attr("checked", "checked"); 
    else 
     $(".radioR").removeAttr("checked"); 
}); 
+0

감사합니다. Andy !!! 당신의 첫 번째 옵션을 사용하고 그것은 챔피언처럼 일했습니다. 라디오 버튼을 선택 취소하고 싶습니다 ...하지만 지금까지 너무 오래 걸렸습니다. 지금 당장 머리가 조금 모자라는 걸 알았습니다. :) – Chnikki

+0

"확인 된"속성을 제거해야한다고 생각하지 않습니다. 어쨌든 한 번에 하나의 라디오 버튼 선택 만 선택할 수 있기 때문에 나머지 코드는 좋아 보인다. –

1

처음에는 내가 확인한 한 XHTML에서 유효한 값으로 확인 만받습니다. 그래서 다음과 같은 것을 정말 $는 ("# ID가")는 document.getElementById를를 필요가 호출되지 않는 등의 입력 요소 필터를 추가로 트릭 모든 라디오 버튼을 제거하기위한 선택의 변화를

$("#RemoveAll").change(function() { 
    if ($(this).is(':checked')) 
      $("input:radio.radioR").attr("checked","checked"); 

    else 
      $("input:radio.radioR").removeAttr("checked"); 
    }); 
}); 

주의해야 .

1

이 당신이 필요로 어떻게해야 ...

$("input.#RemoveAll").click(function() { 

    if ($(this).attr('checked') === "checked"){ 

    $("input:radio[class*='radioR']").attr("checked","checked"); 

    }else{ 

    $("input:radio[class*='radioR']").removeAttr("checked"); 

    } 
}); 

는, 신안 도움이되기를 바랍니다.