Home >Web Front-end >JS Tutorial >JavaScript timer demo

JavaScript timer demo

高洛峰
高洛峰Original
2016-11-25 14:13:281283browse

<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>


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn