2012-06-26 4 views
0

확인란을 클릭하면 입력 상자와 버튼을 비활성화하고 싶습니다.JS - jQuery - 확인란으로 양식 필드 사용 안 함

내 마크 업 :

<h4>Random or Not </h4> 

    <!-- Use Random Image --> 

    <label><input name="o99_aufu_options[o99_aufu_random]" id="o99_aufu_options[o99_aufu_random]" value="1" checked="checked" type="checkbox">Use Random Image ? <em></em></label><br> 

    <!-- If the above not checked - needs to be enabled -->       
    Upload Image <label for="upload_image"> <input id="upload_image" size="36" name="o99_aufu_options[o99_aufu_upload_image]" value="" type="text"> <input id="upload_image_button" value="Choose Image or upload" type="button"> </label> 

jQuery를 : 잘

if (jQuery('#o99_aufu_options[o99_aufu_random]').is(':checked')) { 
     jQuery('#upload_image :input').attr('disabled', true); 
    } else { 
     jQuery('#upload_image_button,#upload_image :input').removeAttr('disabled'); 
    } 

- 분명, 내가 여기 해달라고 부탁하는 경우 - 그것은 :-) 작동하지 않습니다

바이올린 :

http://jsfiddle.net/obmerk99/6jFMf/3/

또한 보너스 질문 - 마크 업에서 ID를 제외하고 입력 이름 만 사용하는 것이 가능합니까?

UPDATE I - 작업 솔루션 :

http://jsfiddle.net/obmerk99/6jFMf/20/

답변

3

보너스 질문 - 마크 업에서 ID를 생략 만 입력의 이름으로 그렇게하는 것이 가능합니까? 당신의 이름은 괄호를 가지고 있기 때문에

$('[name="foo"]) 

하면, 당신은 아마 그들을 탈출해야합니다 :

$('[name="o99_aufu_options\[o99_aufu_random\]"]') 

당신은 이름을 포함하여 jQuery를 선택에 어떤 속성을 사용할 수 있습니다 원할 경우 특정 요소에 한정 할 수도 있고 다른 선택자와 결합 할 수도 있습니다.

$('input.someClass[name="o99_aufu_options\[o99_aufu_random\]"]') 

귀하의 실제 질문에 관해서는, 내 첫번째 추측은 ... 잘못되었습니다 당신의 문제가 공백이다; 시도해 봤어 :

#upload_image:input 

대신에?

.prop('disabled', true); 

당신이 봤어 :

.prop('disabled', 'disabled'); 

내 두 번째 추측은 문제가 있음을 또한 잘못?

좋아, 나는 실제로 당신의 바이올린을 보았고, 몇 가지 잘못이있었습니다; 여기에 실례가 있습니다. 궁금한 점이 있으면 알려주세요. :

jQuery(function() { 
    jQuery('input[name="o99_aufu_options\[o99_aufu_random\]"]').click(function(){ 
     var isChecked = jQuery(this).is(':checked') ; 
     jQuery('#upload_image:input').prop('disabled', isChecked? 'disabled' : null); 
    }) 
}); 
+0

답변을 드리 겠지만 노력하고있는 것은 아닙니다. 작동하지 않는 것 같습니다. –

+0

내 대답을 업데이트했습니다. 내 최근 제안을 검토해 주시겠습니까? – machineghost

+0

고마워 - 잘 작동합니다.문서가로드 될 때만 함수가 그것을 제어하지 못합니다. 기본적으로 "disabled"속성을 추가했습니다 (http://jsfiddle.net/obmerk99/6jFMf/20/ 참조). BTW - "업데이트"를 클릭하여 바이올린 변경 사항을 저장 한 다음 여기에 새 링크를 게시 할 수 있다는 것을 알고 있습니까? –