javascript当中跑马灯的作用

马克- to-win:马克 java社区:防盗版实名手机尾号: 73203。
例 1.9.3(PaoMaDengSelfIEFF.html)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title></title>
    <script type="text/javascript">
        var str="welcome to my website";
        var i=1;
        function pao()
        {
            window.setInterval(repCode,1000);
        }
        function repCode()
        {
            document.getElementById("sp").innerHTML= str.substring(0,i);
 //           window.status= str.substring(0,i);
            i++;
            if(i==str.length) i=1;
        }
    </script>
</head>
<body onload="pao()">
<span id="sp"></span>
</body>
</html>




setTimeout&clearInterval




例 1.9.4(setIntervalTimeout1IEFF.html)



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<SCRIPT LANGUAGE="JavaScript">
<!--
var n=2;
function startNum()
{
 /* 马克-to-win:If you only want to delay the execution of some code and you want it to be executed just once, then use the setTimeout() method instead.1秒以后执行startNum, 所以和setInterval的唯一区别就是那个是执行n次,setTimeout只执行一次。*/
     document.getElementById("num").innerHTML=n
    n++;
    temp = setTimeout("startNum()",1000)
}

function stopNum()
{
    clearInterval(temp)
}

//-->
</SCRIPT>
</HEAD>

<BODY>
<div id="num">0</div>
<INPUT TYPE="button" value="start" onclick="startNum()">&nbsp;&nbsp;<INPUT TYPE="button" value="stop" onclick="stopNum()">
</BODY>
</HTML>