2011-04-27 4 views
1

jquery 함수 내부에서 전역 변수를 어떻게 변경합니까? 아래 코드를 사용하면 "15"가 아니라 "0"이 표시됩니다.jquery 함수 내 전역 변수 변경

<script type> 
theValue=0; 
     $(document).ready(function(){ 
    theValue=15; 
    }); 
</script> 

<script type="text/javascript"> 
    document.write(theValue) 
</script> 
+2

' document.write (theValue)'가 실행됩니다. – Matijs

+0

+1 Matijs의 답변 – Craig

답변

2

그게 전부 당신이 쓸 때 때문에 (문서) .ready은 아직 발사되지 않았습니다. Example는 통지는 0 씁니다하지만 당신은 버튼을 클릭하면 해당 아직 때`때문에 $ (문서) .ready (...)`문서 후 화재가 준비 때문에 theValue이 변경되지 않은 것입니다이다 (15)