Heim > Artikel > Web-Frontend > JavaScript-Timer-Demo
<html> <head> <script type="text/javascript"> var g_percentFlag; var g_percent = 0; var g_count = 0; function intervalPercent(path) { g_count += 1; document.getElementById("msg3").value = g_count; if (g_percent < 100) { g_percent += 20; document.getElementById("msg2").value = g_percent + "%"; } else if (g_percent == 100) { document.getElementById("msg2").value = g_percent + "%"; clearInterval(g_percentFlag); g_percent = 0; } else { document.getElementById("msg2").value = "Error."; } } function getPercentage(path){ g_percentFlag = setInterval("intervalPercent(\"" + path + "\")", 200); } </script> </head> <body> www.2cto.com <!-- <input type="button" value="click" onclick="a=" /> --> <input id="msg2" type="text" /><br /> <input id="msg3" type="text" /><br /> <script> getPercentage("Hello!"); </script> <input type="text" value="nothing" /> <input type="button" value="click" /> </body> </html>