如何增加“i”每7秒1点?往下看。 [英] How do I increase "i" by 1 every 7 seconds? Look below.
问题描述
我需要一些javascript代码的帮助。我需要每7秒做一次i。将增加1.这样我就会得到自从你进入这个网页以来,人们已经因饥饿而死亡。例如。
开始:自从你进入这个网页后,有0人因饥饿而死亡
7秒后:自从你进入这个网页以来,有1人因饥饿而死亡。
又过了7秒:自从你进入这个网页后,有2人因饥饿而死亡。
请帮助!这是我到目前为止所做的。我真的不知道我在做什么。如果可以添加If语句,以便对于i = 1的情况,人有,那将是好的。将更改为人有
I need help for some javascript code. I need to make it so that every 7 seconds, "i" will increase by 1. So that I will get " ''i'' people have died from hunger since you entered this web page." Eg.
Start: 0 people have died from hunger since you entered this web page
After 7 seconds: 1 people have died from hunger since you entered this web page.
After another 7 seconds: 2 people have died from hunger since you entered this web page.
Please help!. This is what I have been doing so far. I don''t really know what I am doing actually. It would be good if a If statement could be added such that for the case of i=1, "people have" will be changed to "person has"
推荐答案
好的, document.write()一定不能用。
你有一个setInterval()太多了(你只需要一个进程来重复)
你没有包含jQuery / prototype(你尝试使用的任何框架)。
一个id不能以hash开头(#) ,这是一个保留关键字在HTML中。
ok, document.write() must not be used.
you have one setInterval() too many (you only need one process to repeat)
you didn’t include jQuery/prototype (whatever framework you try to use).
an id must not start with a hash (#), that’s a "reserved keyword" in HTML.
好的......让我们稍微改一下
Ok...Lets change it a bit
好了,错误的setInterval()被删除了,但是这次逻辑是正确的。你需要做的就是下一步是获得< p>更新(首先尝试没有setInterval())
个人贴:
well, wrong setInterval() deleted, however, the logic is correcter this time. what you need to do as next step is getting the <p> to update (try that first without setInterval())
personal stickie:
这篇关于如何增加“i”每7秒1点?往下看。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!