2012-09-11 2 views
0

진행률 표시 줄로드가 끝나고 끝까지 도달하면 반복적으로 반복하지 않고 별도의 함수 (예 : test())를 실행할 수 있도록 아래 코드를 어떻게 수정할 수 있습니까? 지금이다.진행 표시 줄 반복 유지

<html> 
    <head> 
     <script type="text/javascript"> 
     var prg_width = 200; 

     function progress() { 
      var node = document.getElementById('progress'); 
      var w = node.style.width.match(/\d+/); 

      if (w == prg_width) { 
       w = 0; 
      } 

      node.style.width = parseInt(w) + 5 + 'px'; 
     } 

     </script> 
    </head> 

    <body onload="var progress_run_id = setInterval(progress, 30);"> 

     <div style="border: 1px solid #808080; width:200px; height:5px;"> 
      <div id="progress" style="height:5px; width:0px; background-color:#DBDBDB;"/> 
     </div> 

    </body> 
</html> 

모든 도움에 감사드립니다.

건배 폭이 완성 폭과 동일한지를 확인

제이

답변

0
<html> 
<head> 
<script type="text/javascript"> 
var prg_width = 200; 
var progress_run_id = null; 

function progress() { 
var node = document.getElementById('progress'); 
    var w = node.style.width.match(/\d+/); 
    if (w == prg_width) { 
     clearInterval(progress_run_id); 
     w = 0; 
    } else { 
     w = parseInt(w) + 5 + 'px';    
    } 
    node.style.width = w; 
} 
function initialize(){ 
    progress_run_id = setInterval(progress, 30); 
} 
window.onload = initialize(); 
</script> 
</head> 
<body> 
     <div style="border: 1px solid #808080; width:200px; height:5px;"> 
     <div id="progress" style="height:5px; width:0px; background-color:#DBDBDB;"/> 
     </div> 
</body> 
</html> 
+0

나는 HTML과 자바 스크립트를 별도로 유지하여 대신 window.onload를 사용하는 것을 선호합니다. –

+0

매력처럼 작동했습니다. 오류 없음. 이 세상에 멋진 사람들이 많이 있습니다. 정말 고맙습니다!. –

0
var prg_width = 200; 

     function progress() { 
      var node = document.getElementById('progress'); 
      var w = node.style.width.match(/\d+/); 

      if (w == prg_width) { 
       test(); // CHANGE THIS 
       clearInterval(progress_run_id); 
      } 

      node.style.width = parseInt(w) + 5 + 'px'; 
     } 

. 그런 경우 간격을 지우고 test 기능을 호출하십시오.

1

전화 대신

w = 0;

라인이 별도의 기능. clearInterval(progress_run_id)도 잊지 마세요.

0
<script type="text/javascript"> 
     var prg_width = 200; 

     function progress() { 
      var node = document.getElementById('progress'); 
      var w = node.style.width.match(/\d+/); 

      if (w == prg_width) { 
       test(); 
       clearInterval(progress_run_id); 
      } 

      node.style.width = parseInt(w) + 5 + 'px'; 

     } 

     </script> 
+0

덕분에 ....이는 완료 후 후 벌금과 멋쟁이,하지만 작동하고 내가 그 progress_run_id이 정의되지 말하는 오류가 발생 시험()를 실행? 어떤 아이디어? –