<head>
<title>bbb</title>
<script>
var tmId;
function moveit(){
if((parseInt(document.all.mxh.style.left))>300)
{
document.all.mxh.style.left="0";}
else
{
document.all.mxh.style.left=(parseInt(document.all.mxh.style.left)+3).toString()+"px"}
tmId=setTimeout('moveit()',20)
}</script>
</head>
<body bgcolor="#0099ff">
<div id=mxh style="position:absolute;left:0px;top:0px"><a href="http://lucky.myrice.com" target="_blank"><img src="http://lucky.myrice.com/javabk1.jpg"  border=0></a></div>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><a href=# onclick=moveit()>移动</a>

解决方案 »

  1.   

    如果想让他停止,可以这么做:
    <head>
    <script>
    var tmId;
    function moveit(){
    if((parseInt(document.all.mxh.style.left))>300)
    {
    clearTimeout(tmId);
    }
    else
    {
    document.all.mxh.style.left=(parseInt(document.all.mxh.style.left)+3).toString()+"px"}
    tmId=setTimeout('moveit()',20)
    }</script>
    </head>
    <body bgcolor="#0099ff">
    <div id=mxh style="position:absolute;left:0px;top:0px"><a href="http://lucky.myrice.com" target="_blank"><img src="http://lucky.myrice.com/javabk1.jpg"  border=0></a></div>
    <br><br><br><br><br><br><br><br><br><br><br><br><br><br><a href=# onclick=moveit()>移动</a>