Javascript中暂停功能的实现

None.gif Javascript中暂停功能的实现
None.gif 
None.gif
< script language = " javascript " >
ExpandedBlockStart.gifContractedBlock.gif  
/**/ /*Javascript中暂停功能的实现
InBlock.gif  Javascript本身没有暂停功能(sleep不能使用)同时 vbscript也不能使用doEvents,故编写此函数实现此功能。
InBlock.gif  javascript作为弱对象语言,一个函数也可以作为一个对象使用。
InBlock.gif  比如:
InBlock.gif  function Test(){
InBlock.gif   alert("hellow");
InBlock.gif   this.NextStep=function(){
InBlock.gif    alert("NextStep");
InBlock.gif   }
InBlock.gif  }
InBlock.gif  我们可以这样调用 var myTest=new Test();myTest.NextStep(); 
InBlock.gif  我们做暂停的时候可以吧一个函数分为两部分,暂停操作前的不变,把要在暂停后执行的代码放在this.NextStep中。
InBlock.gif  为了控制暂停和继续,我们需要编写两个函数来分别实现暂停和继续功能。
InBlock.gif  暂停函数如下:
ExpandedBlockEnd.gif  
*/

ExpandedBlockStart.gifContractedBlock.gif  
function  Pause(obj,iMinSecond) dot.gif {
InBlock.gif   
if (window.eventList==null) window.eventList=new Array();
InBlock.gif   
var ind=-1;
ExpandedSubBlockStart.gifContractedSubBlock.gif   
for (var i=0;i<window.eventList.length;i++)dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif    
if (window.eventList[i]==nulldot.gif{
InBlock.gif     window.eventList[i]
=obj;
InBlock.gif     ind
=i;
InBlock.gif     
break;
ExpandedSubBlockEnd.gif    }

ExpandedSubBlockEnd.gif   }

InBlock.gif   
ExpandedSubBlockStart.gifContractedSubBlock.gif   
if (ind==-1)dot.gif{
InBlock.gif    ind
=window.eventList.length;
InBlock.gif    window.eventList[ind]
=obj;
ExpandedSubBlockEnd.gif   }

InBlock.gif   setTimeout(
"GoOn(" + ind + ")",1000);
ExpandedBlockEnd.gif  }

ExpandedBlockStart.gifContractedBlock.gif  
/**/ /*
InBlock.gif  该函数把要暂停的函数放到数组window.eventList里,同时通过setTimeout来调用继续函数。
InBlock.gif
InBlock.gif  继续函数如下:
ExpandedBlockEnd.gif  
*/

None.gif
ExpandedBlockStart.gifContractedBlock.gif  
function  GoOn(ind) dot.gif {
InBlock.gif   
var obj=window.eventList[ind];
InBlock.gif   window.eventList[ind]
=null;
InBlock.gif   
if (obj.NextStep) obj.NextStep();
InBlock.gif   
else obj();
ExpandedBlockEnd.gif  }

ExpandedBlockStart.gifContractedBlock.gif  
/**/ /*
InBlock.gif  该函数调用被暂停的函数的NextStep方法,如果没有这个方法则重新调用该函数。
InBlock.gif
InBlock.gif  
InBlock.gif  函数编写完毕,我们可以作如下册是:
ExpandedBlockEnd.gif  
*/

ExpandedBlockStart.gifContractedBlock.gif  
function  Test() dot.gif {
InBlock.gif   alert(
"hellow");
InBlock.gif   Pause(
this,1000);//调用暂停函数
ExpandedSubBlockStart.gifContractedSubBlock.gif
   this.NextStep=function()dot.gif{
InBlock.gif    alert(
"NextStep");
ExpandedSubBlockEnd.gif   }

ExpandedBlockEnd.gif  }

None.gif  
</ script >
None.gif
None.gif
None.gif

转载于:https://www.cnblogs.com/ctfzh/archive/2007/07/09/811375.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值