"JQuery 버튼 수행시간동안 disabled"의 두 판 사이의 차이

4번째 줄: 4번째 줄:
<source lang='html'>
<source lang='html'>
<style>
<style>
button {width:300px; height:50px; }
  button {
button:disabled { background: #fee; border:0 }
    width: 300px;
    height: 50px;
  }
 
  button:disabled {
    background: #fee;
    border: 0
  }
 
</style>
</style>


12번째 줄: 20번째 줄:
<script src="//code.jquery.com/jquery.min.js"></script>
<script src="//code.jquery.com/jquery.min.js"></script>
<script>
<script>
   function process(num){
   function process(num) {
  $('#my-progress').attr('max', num);
    $('#my-progress').attr('max', num);
     for(var i=1; i<=num; i++) {
     for (var i = 1; i <= num; i++) {
    console.log('processing '+i);
      console.log('processing ' + i);
    // sleep 1 sec
      // sleep 1 sec
       ts1 = new Date().getTime()+100;
       ts1 = new Date().getTime() + 100;
       do ts2 = new Date().getTime(); while (ts2<ts1);
       do ts2 = new Date().getTime(); while (ts2 < ts1);
     }
     }
   }
   }
 
 
   function async_job() {
   function async_job() {
  process(30);
    process(30);
     $('#my-btn').prop('disabled', false);
     $('#my-btn').prop('disabled', false);
   }
   }
33번째 줄: 41번째 줄:
     });
     });
   });
   });
</script>
</script>
</source>
</source>

2016년 12월 1일 (목) 18:26 판

개요

jQuery 버튼 수행시간동안 disabled
<style>
  button {
    width: 300px;
    height: 50px;
  }
  
  button:disabled {
    background: #fee;
    border: 0
  }

</style>

<button id='my-btn'>수행</button>

<script src="//code.jquery.com/jquery.min.js"></script>
<script>
  function process(num) {
    $('#my-progress').attr('max', num);
    for (var i = 1; i <= num; i++) {
      console.log('processing ' + i);
      // sleep 1 sec
      ts1 = new Date().getTime() + 100;
      do ts2 = new Date().getTime(); while (ts2 < ts1);
    }
  }

  function async_job() {
    process(30);
    $('#my-btn').prop('disabled', false);
  }

  $(function() {
    $('#my-btn').click(function() {
      $('#my-btn').prop('disabled', true);
      setTimeout(async_job, 0);
    });
  });

</script>
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}