JQuery 버튼 수행시간동안 disabled

Jmnote (토론 | 기여)님의 2016년 12월 1일 (목) 18:24 판 (새 문서: <source lang='html'> <style> button {width:200px; height:100px; } button:disabled { background: #fee; border:0 } </style> <button id='my-btn'>수행</button> <script src="//code.jq...)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)
<style>
button {width:200px; height:100px; }
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 }}