2013-04-23 3 views
-1

여러 텍스트 상자를 사용하려면 확인란을 만듭니다. 이 옵션을 선택하면 기본적으로 활성화 및 비활성화됩니다.하나의 확인란으로 여러 텍스트 상자 사용 가능

자바 스크립트 코드 :

$(document).ready(function(){ 
    $('#sccb').click(function(){ 
     if (this.checked) { 
      $('#cns').removeAttr("disabled"); 
      $('#cns2').removeAttr("disabled"); 
      $('#cns3').removeAttr("disabled"); 
     } else { 
      $("#cns").attr("disabled", true); 
      $("#cns2").attr("disabled", true); 
      $("#cns3").attr("disabled", true); 
     } 
    }); 
}); 

HTML 코드 :

<input type="checkbox" id="sccb" name="science" value="science"> 
<input type="text" id="cns" name="coornamescience" disabled="disabled" size="30" /> 
<input type="text" id="cns2" name="coornamescience" disabled="disabled" size="30" /> 
<input type="text" id="cns3" name="coornamescience" disabled="disabled" size="30" /> 

그것은 jsfiddle에서 작동하지만,이 .html 파일에서 작동하지 않습니다, 도와주세요.

+3

당신은 내가 추측이 작업 – anpsmn

답변

2

jquery를 추가하는 것을 잊었습니까?

<!DOCTYPE html> 
<html> 
<head> 
<script src="http://code.jquery.com/jquery-1.9.1.js"></script> 
<script type="text/javascript"> 
$(document).ready(function(){ 
    $('#sccb').click(function(){ 
     if (this.checked) { 
      $('#cns').removeAttr("disabled"); 
      $('#cns2').removeAttr("disabled"); 
      $('#cns3').removeAttr("disabled"); 
     } else { 
      $("#cns").attr("disabled", true); 
      $("#cns2").attr("disabled", true); 
      $("#cns3").attr("disabled", true); 
     } 
    }); 
}); 
</script> 
</head> 
<body> 
    <form ...> 
     Your form here 
    </form> 
</body> 
</html> 
+0

를 만들기 위해 jQuery를 포함 할 필요가 jsfiddle 포함 자동 JQuery와 – ElSinus

+0

오, 나는 그것을 포함하는 것을 잊었다, 내가 내가에 자바 스크립트 코드를 삽입 않는 매우 긴 PHP는 양식이있는 경우? @ 엘시 누스 – rapide

+0

이것으로 충분합니까? – ElSinus

관련 문제