<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style>
#main {
width: 608px;
border: solid 1px red;
margin: auto;
} #main .block {
width: 100px;
height: 100px;
line-height: 100px;
text-align: center;
border: solid 1px blue;
margin: 5px 25px;
float: left;
} .blue {
width: 100px;
height: 100px;
line-height: 100px;
text-align: center;
border: solid 1px blue;
background-color: blue;
margin: 5px 25px;
color: white;
float: left;
} </style>
<script type="text/javascript" src="../../js/system.js"></script>
</head>
<body>
<div id="main">
<div class="block" id="a1">a</div>
<div class="block" id="a2">b</div>
<div class="block" id="a3">c</div>
<div class="block" id="a4">d</div>
<div class="block" id="a8">e</div>
<div class="block" id="a7">f</div>
<div class="block" id="a6">g</div>
<div class="block" id="a5">h</div>
<div style="clear: both"></div>
</div>
<input type="button" id="btnStop" value="停止">
<input type="button" id="btnBegin" value="开始">
<script type="text/javascript">
var index = 0;
var bojGame = null;
$$("btnBegin").onclick = function () {
clearInterval(bojGame);
bojGame = setInterval(function () { //按照指定的周期来调用好函数或表达式,以毫秒计算1000毫秒=1秒,,循环的
for (var i = 1; i <= 8; i++) {
var n = "a" + i;
comm.setAttr($$(n), "class", "block");
}
index++;
var n = "a" + index;
comm.setAttr($$(n), "class", "blue");
if (index >= 8) {
index = 0;
}
}, 100)
} $$("btnStop").onclick = function () {
clearInterval(bojGame); //退出循环
}
</script>
</body>
</html>

setInterval和clearInterval的更多相关文章

  1. JavaScript--定时器setTimeout()、clearTimeout(var param)和setInterval()、clearInterval(var param)

    1.setTimeout().clearTimeout(var param) setTimeout() 方法用于在指定的毫秒数后调用函数或计算表达式,只调用一次 clearTimeout() 方法可取 ...

  2. setInterval 与 clearInterval详解

    首先注意,setInterval与clearInterval都是直属于window对象的. 1.直接调用setInterval(即不通过函数调用) <div id="oDiv_show ...

  3. JS不间断向上滚动 setInterval和clearInterval

    <div id=demo style=overflow:hidden;height:139;width:232;background:#f4f4f4;color:#ffffff><d ...

  4. 用javascript编写的小游戏(getElementById , setInterval , clearInterval , window.onload , innerText 和页面跳转, 标签的使用)

    (1)图片轮转 <script type="text/javascript" > ; setInterval(function(){ var dom=document. ...

  5. setInterval setTimeout clearInterval

    setTimeout() 只执行 code 一次.如果要多次调用,请使用 setInterval() 或者让 code 自身再次调用 setTimeout(). //第一次load的时候就先刷新一次 ...

  6. (二)学习JavaScript之setInterval和clearInterval方法

    参考:http://www.w3school.com.cn/jsref/met_win_setinterval.asp HTML DOM Window 对象 定义和用法 setInterval() 方 ...

  7. js setInterval和clearInterval 的使用

    setInterval(函数名, 时间);   函数名:不需要加括号:  时间:单位是毫秒: 例子: var inter= setInterval(searchTasksByCnd, 10 * 100 ...

  8. setInterval()、clearInterval()、setTimeout()和clearTimeout()js计数器方法

    原文地址:http://caibaojian.com/setinterval-settimeout.html window.setInterval()方法 介绍 周期性地调用一个函数(function ...

  9. setInterval()与clearInterval()的用法

    setInterval() 方法可按照指定的周期来调用函数或计算表达式.  --简单地说就是过一段时间调用一次该函数 setInterval() 方法会不停地调用函数,直到 clearInterval ...

随机推荐

  1. LeetCode 2 Add Two Numbers 模拟,读题 难度:0

    https://leetcode.com/problems/add-two-numbers/ You are given two linked lists representing two non-n ...

  2. java时间戳

    1.时间戳的定义 时间戳是指文件属性里的创建.修改.访问时间. 数字时间戳技术是数字签名技术一种变种的应用.在电子商务交易文件中,时间是十分重要的信息.在书面合同中,文件签署的日期和签名一样均是十分重 ...

  3. μC/OS-Ⅲ系统的源代码文件组织结构

  4. sql之多表连接

    最近遇到特别多多表连接的问题,因此随笔记下,开始学java和mysql的时间太短,有见解不周的地方,希望读者可以提出探讨. 对于left join.right join和inner join(join ...

  5. GDAL C# 开发出现的异常

    在使用开发C#下的GDAL时,编译时正确. 在执行 Gdal.AllRegister(); 出现异常:OSGeo.GDAL.GdalPINVOKE”的类型初始值设定项引发异常. 解决方案: 编译正常, ...

  6. [导读]Learning from Imbalanced Classes

    原文:Learning from Imbalanced Classes 数据不平衡是一个非常经典的问题,数据挖掘.计算广告.NLP等工作经常遇到.该文总结了可能有效的方法,值得参考: Do nothi ...

  7. eclipse + python dev

    错误:Project interpreter not specified解决方法 http://blog.csdn.net/magictong/article/details/7288732 安装Py ...

  8. JS实现登陆验证的主要代码及思路

    window.onload = function(){ // 获取input标签 var alInput = document.getElementsByTagName("input&quo ...

  9. 如何使用.NET开发全版本支持的Outlook插件产品(一)——准备工作

    这半年一直在做Outlook的插件,因为不会VC++,所以想找一款基于.NET,用C#开发Outlook插件的技术方案.没想到,光技术选型这件事,就用各种技术手段验证了将近一个月,还花费了大量的精力做 ...

  10. tail 显示文件最后若干行内容

    功能:tail命令可以输出文件的尾部内容,默认情况下它显示文件的最后十行.显示每个指定文件的最后10 行到标准输出.若指定了多于一个文件,程序会在每段输出的开始添加相应文件名作为头.如果不指定文件或文 ...