我想做一个按钮!鼠标指在上面是一种颜色!点击后是另一种颜色,并能保持该颜色,点击功能结束后恢复默认颜色!一开始一种颜色!

解决方案 »

  1.   


    <body>
    <input id="bt" type="button" value="我是一个按钮,你们来蹂躏我的颜色吧!">
    <script type="text/javascript">
    <!--//
    var $=function(o){return document.getElementById(o);};
    $("bt").style.background="#FFFF00"; //默认颜色
    $("bt").onmouseover=function(){ //鼠标指在上面是蓝色,松开恢复默认颜色
    this.style.background="blue";
    $("bt").onmouseout=function(){
    this.style.background="#FFFF00";
    };
    };$("bt").onmousedown=function(){ //按下红色,松开恢复默认颜色
    this.style.background="red";
    $("bt").onmouseup=function(){
    this.style.background="#FFFF00";
    };
    };
    //-->
    </script>