首页 >web前端 >js教程 >JavaScript定时器演示

JavaScript定时器演示

高洛峰
高洛峰原创
2016-11-25 14:13:281281浏览

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


声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn