DOM refresh on long running function

后端 未结 12 2322
醉话见心
醉话见心 2020-11-27 20:54

I have a button which runs a long running function when it\'s clicked. Now, while the function is running, I want to change the button text, but I\'m having problems in some

12条回答
  •  萌比男神i
    2020-11-27 21:24

    SOLVED IT!! No setTimeout()!!!

    Tested in Chrome 27.0.1453, Firefox 21.0, Internet 9.0.8112

    $("#btn").on("mousedown",function(){
    $('#btn').html('working');}).on('mouseup', longFunc);
    
    function longFunc(){
      //Do your long running work here...
       for (i = 1; i<1003332300; i++) {}
      //And on finish....  
       $('#btn').html('done');
    }
    

    DEMO HERE!

提交回复
热议问题