Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/471.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为什么SetInterval不';t工作(只工作一次)_Javascript_Jquery_Setinterval - Fatal编程技术网

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不,不,现在一切正常,谢谢,很好,但请不要编辑您的问题,用答案中的代码替换损坏的代码,因为当人们稍后阅读您的问题时,它没有意义。我已回滚您的编辑。