JavaScript定时器演示
程序员文章站
2022-03-29 10:01:48
...
<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>
上一篇: 如何在html中更改行间距