问题
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