2013-04-23 4 views
0

필드 세트에 2 개의 라디오 버튼이 있습니다. 두 번째 라디오가 선택되면 조건을 적용하려고 시도하지만 작동하지 않습니다. 방화 광 콘솔을 사용하여 ID로 두 요소를 얻으면 두 요소를 검사한다고합니다.라디오 버튼이 선택된 상태가 작동하지 않습니다.

내 코드 :

<fieldset data-role="controlgroup" data-type="horizontal" data-role="fieldcontain"> 
    <input type="radio" name="soci1" id="sisoci1" value="soci1"/> 
    <label for="sisoci1">Soci/Abonat</label> 

    <input type="radio" name="soci1" id="nosoci1" value="nosoci1"/> 
    <label for="nosoci1">Convidat</label> 
</fieldset> 

내 기능 :

if(document.getElementById("nosoci1").checked=true){ 
     check_soci1="no_soci"; 
    }else{ 
     check_soci1="soci"; 
    } 

파이어 버그의 말씀 :

>>> document.getElementById("sisoci1") 
    <input id="sisoci1" type="radio" value="soci1" name="soci1" checked="checked"> 
    >>> document.getElementById("nosoci1") 
    <input id="nosoci1" type="radio" value="nosoci1" name="soci1" checked="checked"> 

은 누구도 날 도와 드릴까요? 감사.

if(document.getElementById("nosoci1").checked == true) { ... } 

하거나 아예 비교를 건너 :

+0

== 비교입니다. = 함께 체크 된 값을 true로 설정하십시오. –

답변

2

비교를 사용하려면 두 번 == 기호를 필요

if(document.getElementById("nosoci1").checked) { ... } 

코드가 하나의 = 기호, 작성 방법 ' checked '속성에 true 값이 할당 된 다음 if 비교가 해당 값에서 실행됩니다. 실제로는 항상 true으로 평가됩니다.

+0

OMFG, WTF. 나는 너무 어리 석다 ... 오늘 나는 그 어느 때보 다 잠 들어있다 ... 정말 고마워 내 초보자 오류! – Angel

관련 문제