2016-12-09 1 views
-1

두 개의 라디오 버튼을 클릭하면 텍스트 영역을 활성화/비활성화하는 데 jQuery를 사용하고 있습니다. 나는 텍스트 영역이 무효가되어 있다는 것입니다보고, 다시 활성화 얻을 수 없다 무엇을 실제로텍스트 영역 활성화/비활성화

<form> 
    <input type="radio" id="aa" name="candidates">1 <br> 
    <input type="radio" id="bb" name="candidates">2<br> 
</form> 
<textarea rows="2" id="candidateTextArea" style="width: 100%;">adadsajsd</textarea> 

jQuery를

$("#aa").change(function() { 
        console.log("change in aa"); 
      $("#candidateTextArea").attr("disabled", "true"); 
     } 
); 

$("#bb").change(function() { 
        console.log("change in bb"); 
      $("#candidateTextArea").attr("disabled", "false"); 
     } 
); 

http://jsfiddle.net/uu1kje5x/5/

HTML : 여기 내 코드입니다. 이 아이디어가 효과가없는 이유는 무엇입니까?

+0

가능한 복제 (HTTP 장애인 속성을 제거해야합니다 : /을 /stackoverflow.com/questions/1414365/disable-enable-an-input-with-jquery) – Pineda

답변

1

"false" 대신 false이어야합니다. false

$("#aa").change(function() { 
        console.log("change in aa"); 
      $("#candidateTextArea").attr("disabled", "disabled"); 
     } 
); 

$("#bb").change(function() { 
        console.log("change in bb"); 
      $("#candidateTextArea").attr("disabled", false); 
     } 
); 

Here 따옴표의 필요가 바이올린

0

대신의 속성은 소품 설정 설정입니다 :

$("#aa").change(function() { 
       console.log("change in aa"); 
     $("#candidateTextArea").prop("disabled",true); 

    } 

을);

$("#bb").change(function() { 
       console.log("change in bb"); 
     $("#candidateTextArea").prop("disabled",false); 
    } 
); 
0

비활성화 된 속성이 적용된 HTML 요소를 다시 사용하려면 속성을 완전히 제거해야합니다.

jQuery의 .removeAttr()을 false로 설정하는 대신이 방법을 사용할 수 있습니다.

$("#bb").change(function() { 
    console.log("change in bb"); 
    $("#candidateTextArea").removeAttr("disabled"); // <------ used here 
    } 
);
0

당신은 attr()를 사용하여 disabled 속성을 추가하고 사용 removeAttr()

$("#aa").change(function() { 
 
    $("#candidateTextArea").attr("disabled", "disabled"); 
 
}); 
 

 
$("#bb").change(function() { 
 
    $("#candidateTextArea").removeAttr("disabled"); 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<form> 
 
    <input type="radio" id="aa" name="candidates">1 
 
    <br> 
 
    <input type="radio" id="bb" name="candidates">2 
 
    <br> 
 
</form> 
 
<textarea rows="2" id="candidateTextArea" style="width: 100%;">adadsajsd</textarea>

[사용 안 함/jQuery로 입력을 가능하게?]의