2013-04-17 5 views
1

나는 모든 곳을 뒤지고 모든 종류의 스크립트를 시도했지만 동일한 문제가 계속 발생합니다.javascript가 모든 브라우저에서 작동하지 않습니다

확인란을 선택하지 않으면 제출 단추를 사용하지 않도록 설정하거나 숨기려고합니다.

내가 가지고있는 문제는 호환성이 켜져 있지 않으면 IE 10에서 아무 것도 작동하지 않고 FF 20.0.1에서 대부분 작동하지 않는다는 것입니다.

여기까지 제가 시도한 내용입니다.


<script type='text/javascript' src='http://code.jquery.com/jquery-1.7.1.js'></script> 
<script type='text/javascript'>//<![CDATA[ 
$(window).load(function(){ 
$("#terms").click(function() { 
    if ($(this).is(':checked')) { 
     $('#agreed').removeAttr('disabled'); 
    } else { 
     $('#agreed').attr('disabled', 'disabled'); 
    } 
}); 

});//]]> 

</script> 

      <input type="checkbox" class="required" id="terms"/>Do you Agree? &nbsp; 
      <input type="submit" name="agreed" id="agreed" value="{L_AGREE}" class="button1" disabled="disabled" /> 

나는 그것을 할 수있는 많은 많은 다른 방법을 시도했지만 여전히 IE10 또는 FF 중 하나를 문제로 실행 한


<script type="text/javascript"> 
function checkSubmit(ele, id) { 
    x = document.getElementById(id); 
    if (ele.checked == true) x.disabled = false; 
    else x.disabled = true; 
} 
</script> 

<input type="checkbox" name="myCheck" onclick="checkSubmit(this, 'agreed')" value="y" />Do you Agree? &nbsp; 
<input type="submit" name="agreed" id="agreed" value="{L_AGREE}" class="button1" disabled="disabled" /> 
<input type="checkbox" name="agree" value="yes" onclick="agreed.disabled = !this.checked" />Do you Agree? &nbsp; 
    <input type="submit" name="agreed" id="agreed" value="{L_AGREE}" class="button1" disabled="disabled" /> 


.

내가 필요한 것은 모든 브라우저에서 작동하도록 도움을주는 것입니다.

답변

2

첫 번째 예는 요소를 ID를 통해 window 또는 document 개체에 넣는 지에 따라 다른 브라우저가 아닌 일부 브라우저에서 작동 할 가능성이 높습니다.

수정하려면 document.getElementById()을 사용하십시오.

<input type="checkbox" name="agree" value="yes" onclick="document.getElementById('agreed').disabled = !this.checked" />Do you Agree? &nbsp; 
<input type="submit" name="agreed" id="agreed" value="{L_AGREE}" class="button1" disabled="disabled" /> 

함수가 전역으로 두 번째는 당신이 그것을 단축 할 수 있지만, 한 모든 브라우저에서 작동합니다.

function checkSubmit(ele, id) { 
    document.getElementById(id).disabled = !ele.checked; 
} 
+0

환영합니다 ... – gdoron

+0

@gdoron : 너와 같아! :-) 내가 얼마나 오래 돌아올 지 확신하지 못하지만, 나는 게으른 사람들에게 까다 롭다는 것을 놓친다. –

+0

글로벌이란 무엇입니까? –

관련 문제