<!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. Openwrt 编译报错:rootfs image is too big解决方法

    修改: tools/firmware-utils/src/mktplinkfw2.c static struct flash_layout layouts[] = { { .id = "8M ...

  2. C++小项目:directx11图形程序(九):总结

    整篇文章中对于directx11的知识的介绍并不多,我也不知道怎么介绍,也应该说对于directx,它有它自己的部分,比如设备(device),设备上下文(devicecontext),顶点缓存,索引 ...

  3. 初始化git远程仓库步骤

    Git global setup git config --global user.name "bingo" git config --global user.email &quo ...

  4. curl post

    //Post方式实现 $url = "http://localhost/web_services.php"; $post_data = array ("username& ...

  5. Unity3d之个性化鼠标

    代码实例: using UnityEngine; using System.Collections; public class CursorController : MonoBehaviour { / ...

  6. C++与Java的语法区别

    C++与Java的语法区别 首先,两个大的不同是主函数和怎样编译的不同,接下来是许多小的区别. main 函数C++//自由浮动的函数int main( int argc, char* argv[]) ...

  7. Python的平凡之路(15)

    一.CSS补充: 1. 上节课讲述 a.css重用               <style>            如果整个页面的宽度 > 900px时:            { ...

  8. git中.gitignore配置项不起作用-解决办法

    在某个git项目中,.gitignore忽略了*.iml,但是git status命令依然列了出来,最后发现是由于git的缓存造成的. git rm -r --cached . git add . g ...

  9. Celery 框架学习笔记

    在学习Celery之前,我先简单的去了解了一下什么是生产者消费者模式. 生产者消费者模式 在实际的软件开发过程中,经常会碰到如下场景:某个模块负责产生数据,这些数据由另一个模块来负责处理(此处的模块是 ...

  10. Android Studio 常用快捷键

     继承Eclipse的快捷键 : File->Settings->Keymap->有一个Keymaps 下拉菜单,选择Eclipse.    这里讲主要常用的快捷键 :  Ctrl ...