<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>走马灯</title>
    <style type="text/css">
     body{
margin:0px;}
#box{
border:solid #000 1px;
background-color:#999;
width:300px;
height:180px;
margin:10px;}
#id1,#id2{
border:solid #000 1px;
height:1.25em;
background-color:#FFF;
margin:10px;
margin-top:30px;}
    </style>
    <script type="text/javascript">
            function tryoo(id)
{
_this={};
this.id=id;
this.value=0;
this.start=function()
{
_this[id]=this;
this.inv=setInterval("_this['"+id+"'].roll()",1000);
}
this.roll=function()
{
document.getElementById(this.id).innerHTML=this.id+"="+this.value;
this.value++;
}
}
        </script>
</head><body>
<div id="box">
        <div id="id1"></div>
        <div id="id2"></div>
        <script type="text/javascript">
         o1=new tryoo("id1");
o1.start();
o2=new tryoo("id2");
o2.start();
        </script>
    </div>
</body></html>

解决方案 »

  1.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>走马灯</title>
        <style type="text/css">
            body{
                margin:0px;}
            #box{
                border:solid #000 1px;
                background-color:#999;
                width:300px;
                height:180px;
                margin:10px;}    
            #id1,#id2{
                border:solid #000 1px;
                height:1.25em;
                background-color:#FFF;
                margin:10px;
                margin-top:30px;}
        </style>
        <script type="text/javascript">
    var _this={};
                function tryoo(id)
                    {
                    this.id=id;
                    this.value=0;
                    this.start=function()
                        {
                        _this[id]=this;
                        this.inv=setInterval("_this['"+id+"'].roll()",1000);
                        }
                    this.roll=function()
                        {
                        document.getElementById(this.id).innerHTML=this.id+"="+this.value;
                        this.value++;
                        }
    }
            </script>
    </head><body>
        <div id="box">
            <div id="id1"></div>
            <div id="id2"></div>
            <script type="text/javascript">
                o1=new tryoo("id1");
                o1.start();
                o2=new tryoo("id2");
                o2.start();
            </script>
        </div>
    </body></html>