在注册一个鼠标移出事件
onmouseout 执行和  mouseup 一样

解决方案 »

  1.   

    我是覺得能不用js就不用js樓主提供的正確的示例應該是用css而已
    :hover{
        background-position: 0px -122px;
    }
    :active{
        background-position: 0px -244px;
    }
      

  2.   

    因为你的mousedown和mouseup是注册在某个元素上的  当移出这个元素时就不触发这个元素的mouseup了啊
    <!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>
    <script type="text/javascript">
    window.onload=function(){
    var div=document.getElementById('test');
    div.onmousedown=function(){
    div.style.backgroundColor='black';
    }
    document.body.onmouseup=function(){
    div.style.backgroundColor='red';
    }
    }
    </script>
    </head><body>
    <div id="test" style="width:400px; height:400px; background-color:#F00"></div>
    </body>
    </html>onmouseup注册到父元素上试试