sunyaling
  <script > 
function musicPlay() 
{ alert(
"asdf");
  document.MUSIC1.play(); 
  setTimeout(
"musicStop()",500);

function musicStop() 

  document.MUSIC1.stop(); 
}
</script> 
 
</HEAD>

 
<BODY>
<EMBED NAME="MUSIC1" SRC="msg.wav" Loop=-1  AUTOSTART=false Hidden=true MASTERSOUND> 
 
</BODY>
 
<script>
  musicPlay() ; 
</script>

 

区别:setTimeout("function",time);//设置一个超时对象,只执行一次,无周期 
         setInterval("function",time);//设置一个超时对象,周期=\'交互时间\'

停止定时:clearTimeout(对象) 清除已设置的setTimeout对象
            clearInterval(对象) 清除已设置的setInterval对象

setInterval 不断地执行指定代码直到调用clearInterval清除定时器对象

setTimeout 执行一次指定代码,使用clearTimeout清除定时器对象

setInterval和setTimeout都返回定时器对象标识符,用于clearInterval和clearTimeout调用

举个简单的例子:

 function show(){
trace("每隔一秒我就会显示一次");
}
var sh;
sh=setInterval(show,1000);
clearInterval(sh);

分类:

技术点:

相关文章:

  • 2021-09-17
  • 2021-08-15
  • 2020-03-12
  • 2021-12-28
  • 2021-12-18
  • 2021-10-28
  • 2021-12-28
猜你喜欢
  • 2021-11-12
  • 2021-12-18
  • 2021-09-28
  • 2021-09-01
  • 2021-09-01
  • 2021-04-18
  • 2021-12-18
相关资源
相似解决方案