javascript - Why is my jQuery Function in a function not starting? -


i learning javascript/jquery today, , having trouble stopwatch trying make. here code:

$(document).ready(function () {      var value = 0.0;      $("#startstop").click(function () {          $(this).css("value", "stop");          while (true) {              value += 0.1;              $("#time").delay(100).html(value);              $(this).click(function () {                  $(this).css("value", "start");                  break;              });          }      });  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>  <!doctype html>  <html>      <head>          <title>jquery testing facilities</title>      </head>      <body>          <input id="startstop" type="button" value="start"></input>          <br>          <p id="time">0.0</p>          <script type="text/javascript" src="jquery.js"></script>          <script type="text/javascript" src="onload.js"></script>      </body>  </html>

the problem having doesn't start, value of button doesn't change. tried doing out second onclick function, have no way of stopping it, , browser lags out.

supposedly, neils bohr once dismissed proposal with, “your theory not right. it's not wrong.”

your code off-base , not possibly work.

what trying is

 while (true)      wait 100ms     update screen 

the code wrote couldn't that, because delay function not think does. isn't problem.

the real problem is, javascript single-threaded. if possible "wait", entire browser lock up. (which why javascript tries not allow @ all.)

in single-threaded environment, following:

 on start click    set go variable true    call tick function   on stop click    set go variable false   define tick     if go variable true        update screen        set timer invoke tick function in 100ms 

because seems within abilities, i'll leave write javascript you, except point out set timer in last step code settimeout(tick, 100);

good luck.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -