Javascript Timer Runs Sporadically

戏子无情 提交于 2019-12-13 05:30:12

问题


I am developing a messaging system and through discussion here: webBrowser.Document.Write() Irregular Performance I decided to rewite some of the core login in my program in Javascript.

The demo seen here: http://nathantornquist.com/code/misc/index6.html runs perfectly when you are adding messages from John. As soon as you add a message from Jack, the timer gets messed up and the color of the date on John's messages stop changing.

Can anyone see a clear reason why?


回答1:


Did you check the console in Firefox or Chrome? I checked it out and got an error when clicking "Add a message from Jack"

Uncaught ReferenceError: black is not defined
switchColorindex6.html:74
(anonymous function)

Is black a variable that should be defined?




回答2:


On lines 74 and 76 you have black not quoted, e.g.

        if (!elements[i].style.color!=black)

Try quoting it:

        if (!elements[i].style.color!="black")



回答3:


You have some errors in lines 72-78. One is that you compare color to black which is undefined. Probably it should be 'black'. Second is elements[i].stlye on line 76.



来源:https://stackoverflow.com/questions/8595125/javascript-timer-runs-sporadically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!