javascript - Update a Element's Value On An Interval -


To display me in a Div "display", just need a temperature counter, the default is the temporary 7.2, and whenever I am another temporary When I make a deposit, it gradually decreases (0,2 per 5 minutes), which is for a favorite change Can you help me? I am making a start, please support me. What's wrong with this code?

Javascript:

  var temp = 7.2; Var Loop = Set interval (cooler, 300000); Function Cooler () {document.getElementById ("Display"). InnerHTML = temp-0,2; SetInterval (loop); } Function abortTimer () {clear interval (loop); }  

HTML:

  & lt; Body & gt; Current temporary & lt; Div id = "display" & gt; & Lt; / Div & gt; & Lt; Br> & Lt; Form & gt; Set Temp: & lt; Input type = "text" id = "setTemp" & gt; & Lt; Input type = "submit" value = "submit" onClick = cooler (); & Gt; & Lt; / Form & gt; & Lt; / Body & gt;  

Some things were wrong with the code.

  1. You reduced the temporal value but never updated the variable. (Temp)
  2. You need to use it only once using the interlabel set. Once you become clear, you will need to call it again.

I changed the code slightly, and more appropriate to update the variable names. The code could definitely use some more love, but I kept my changes simple so that you can go along.

Javascript:

  var currentTemp = 7.2; Var Loop = Set Interval (cooler, 1000); Function Cooler () {currentTemp = currentTemp - 0.2; Document.getElementById ("Display"). InnerHTML = currentTemp; } Function setTemp () {var input = document.getElementById ('setTemp'); CurrentTemp = parseInt (input.value); Input.value = ''; } Function abortTimer () {clear interval (loop); } // Click the wire button, submit the button document.getElementById ('submit'). AddEventListener ('click', function () {setTemp ();});  

HTML:

  & lt; Body & gt; Current temporary & lt; Div id = "display" & gt; & Lt; / Div & gt; & Lt; Br> & Lt; Form & gt; Set Temp: & lt; Input type = "text" id = "setTemp" & gt; & Lt; Input id = "submit" type = "button" value = "submit" & gt; & Lt; / Form & gt; & Lt; / Body & gt;  

See the link below for a sample of code running on 1 second update.


Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -