欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  web前端

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>
相关标签: JavaScript