js中的setInterval函数

js中,setInterval函数:setInterval(code,milliseconds,[可选参数])

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>Interval</title>
    <style type="text/css">
        html,body{
            width: 100%; height: 100%;padding: 0; margin: 0;
        }
    </style>
</head>
<body>
<script type="text/javascript">
    var i=1;
    function myFun (str){
        if(i%2===0){
            console.log(str[1]);
        }else{
            console.log(str[0]);
        }
        if(++i>100){
            cleartInterval(timer);
        }
    }
    var timer=setInterval(myFun,1000,["单数","双数"]);
</script>
</body>
</html>

 

posted @ 2017-03-10 14:44  甘小春  Views(639)  Comments(0)    收藏  举报