Javascript 为什么SetInterval不';t工作(只工作一次)
我为Javascript 为什么SetInterval不';t工作(只工作一次),javascript,jquery,setinterval,Javascript,Jquery,Setinterval,我为.swf制作了一个进度条 代码在: function ProgressBar(){ setTimeout(function (){ if (swfobject.getObjectById("Object").IsPlaying()) { var TotalFrames = swfobject.getObjectById("Object").TotalFrames(); console.log(console.log("TotalFrames: " + TotalFrames)); v
.swf
制作了一个进度条
代码在
:
function ProgressBar(){
setTimeout(function (){
if (swfobject.getObjectById("Object").IsPlaying()) {
var TotalFrames = swfobject.getObjectById("Object").TotalFrames();
console.log(console.log("TotalFrames: " + TotalFrames));
var TCurrentFrame = swfobject.getObjectById("Object").CurrentFrame;
console.log(TCurrentFrame);
}
}, 200);
}
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="600" height="600" id="Object">
<param name="movie" value="./Flash.swf">
<param name="wmode" value="transparent">
<param name="loop" value="false">
<param name="play" value="false">
<param name="quality" value="high">
<!--[if !IE]>-->
<object type="application/x-shockwave-flash" data="./Flash.swf" width="600" height="600" id="Object">
<param name="wmode" value="transparent">
<param name="loop" value="false">
<param name="play" value="false">
<param name="quality" value="high">
</object>
<!--<![endif]-->
</object>
代码在
:
function ProgressBar(){
setTimeout(function (){
if (swfobject.getObjectById("Object").IsPlaying()) {
var TotalFrames = swfobject.getObjectById("Object").TotalFrames();
console.log(console.log("TotalFrames: " + TotalFrames));
var TCurrentFrame = swfobject.getObjectById("Object").CurrentFrame;
console.log(TCurrentFrame);
}
}, 200);
}
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="600" height="600" id="Object">
<param name="movie" value="./Flash.swf">
<param name="wmode" value="transparent">
<param name="loop" value="false">
<param name="play" value="false">
<param name="quality" value="high">
<!--[if !IE]>-->
<object type="application/x-shockwave-flash" data="./Flash.swf" width="600" height="600" id="Object">
<param name="wmode" value="transparent">
<param name="loop" value="false">
<param name="play" value="false">
<param name="quality" value="high">
</object>
<!--<![endif]-->
</object>
我想要输出TotalFrame
和CurrentFrame
,但是函数SetInterval
只显示一次结果
控制台日志中的输出:
$("#button").on("click", function(){
ProgressBar();
})
TotalFrames: 745
undefined
102
我该怎么写?错误是什么?您的
ProgressBar
函数使用的是setTimeout()
,而不是setInterval()
setTimeout()
只触发一次超时。可能是因为您没有像在问题标题中那样使用setInterval
,而是在代码中使用setTimeout
) @NikTip没问题;)确保你了解两者之间的区别。另外,请注意,您实际上可以使用setTimeout
,但您必须在每个setTimeout
回调中启动一个新的计时器,以创建所需的效果。关于您编辑的问题:您是说,即使将setTimeout()改为setInterval()
,它仍然不起作用吗
您最初拥有的?@nnnnnn不,不,现在一切正常,谢谢,很好,但请不要编辑您的问题,用答案中的代码替换损坏的代码,因为当人们稍后阅读您的问题时,它没有意义。我已回滚您的编辑。