<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>
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);