2011-02-04 9 views
1

내가 라디오 버튼 그룹 (아래 코드 참조)이 있습니다라디오 버튼 그룹

<tr> 
       <td> 
        Total Meter : 
       </td> 
       <td style="width:10px;"></td> 
       <td> 
        <input type="radio" name="rdoInput" value="Yes" style="border-style:none;" /> Yes 
       </td> 
       <td style="width:10px;"></td> 
       <td>  
        <input type="radio" name="rdoInput" value="No" style="border-style:none;" /> No 
       </td> 
      </tr> 

내 질문입니다, 어떻게 설정하고이 값을받을 수 있나요? 값을 설정하기 위해이 구문을 시도했지만 작동하지 않습니다.

if (msg.d.Input == true) { 
         $('input[name="rdoInput"]').attr('checked', true); 
        } 
        else { 
         $('input[name="rdoInput"]').attr('checked', false); 
        } 

어떤 도움을 주시면 감사하겠습니다!

+3

그 테이블 레이아웃이 ... 특히 빈 셀 놀랍다 패딩 왼쪽을 에뮬레이션합니다. ': D' –

+0

작동하지 않습니까? 오류가 발생했다는 뜻입니까? –

답변

2
$("input[name='rdoInput'][value='Yes']").attr("checked", true); 

또는

$("input[name='rdoInput']:eq(0)").attr("checked", true); 

더 좋은 방법 :

var value = sg.d.Input ? "Yes" : "No"; 

// set the value 
$("input[name='rdoInput'][value='" + value + "']").attr("checked", true); 

// get the value 
var checkedValue = $("input[name='rdoInput']:checked").val(); 

작업 예 : http://jsfiddle.net/xVDxZ/1/

+0

+1, 오렌지 바가 나를 때릴 때까지 [value =]를 지정하려고했습니다. ; p –

+0

질문 : 라디오 버튼 그룹의 값을 얻는 방법 ... –

+0

"getter" – hunter

1

사용 EQ (N) :

$('input[name="rdoInput"]').eq(0).attr('checked', true); 
0

그룹에서 현재 선택 라디오 버튼의 값을 얻기 위하여, 이것을 사용 :

$('input:radio[name="rdoInput"]:checked').val() 
관련 문제