使用java脚本创建时间。 [英] Create time using java script.

查看:55
本文介绍了使用java脚本创建时间。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在java脚本中使用循环和睡眠功能(睡眠是c语言的功能)创建一个时间。



我尝试过:



我试过但无法增加或减少运行循环的速度,所以这里有问题。 kinldy在java脚本中共享完整的源代码。

i want to create a time using loop and sleep function(sleep is function of c language) in java script.

What I have tried:

i've tried but could not increase or decrease speed of running loop, so here is problem. kinldy share full source code in java script.

推荐答案

我想你想制作一个动画时钟。

不要使用循环动画,改为使用计时器。注意你设置计时器的方式以防止时间滑动。



如何JS动画 [ ^ ]



[更新]

I guess you want to make an animated clock.
Don't use a loop to animate, use a timer instead. pay attention to the way you set the timer to prevent time sliding.

How To JS Animate[^]

[Update]
引用:

您提供的参考文献不符合我的问题的回复或含义

the reference you've given does not meet my question's reply nor meaning

首先,您的问题的措辞不明确。 时间在上下文中没有任何意义,这是问题的关键词。

其次,你想向JS申请一个没有的解决方案JS中存在。

第三,发布你的代码将有助于理解你想要做什么,但你没有。

First of all the wording of your question is not clear. time have no meaning in the context and it is the key word of the question.
Second, you want to apply to JS a solution that doesn't exist in JS.
Third, posting your code would have help understand what you are trying to do, but you didn't.


检查这些< br $>


Window setInterval()方法 [ ^ ]

窗口setTimeout()方法 [ ^ ]





check these

Window setInterval() Method[^]
Window setTimeout() Method[^]


var items = [1, 2, 3, 4, 5];
        var time = 1000 // milliseconds        
        var i = 0;
        var loop = window.setInterval(function () { 
            processItem(items[i]);
            i++;
            if (i == items.length)
                clearInterval(loop);
        }, time);

        function processItem(item) // this function wil be called for each item in the array at the  specified time.
        {
            document.getElementById('txtData').value = item;
        }





演示: JSFiddle [ ^ ]


这篇关于使用java脚本创建时间。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆