这个想了好久不回 我是个初学者~~~ 一定要是js或者jq的代码啊

解决方案 »

  1.   

    <script type="text/javascript">
    function change(){
    var a=document.getElementById("test");
    var t=a.getAttribute("num");
    if(t=="1"){
    a.style.backgroundColor="black";
    a.style.color="white";
    }else{
    a.style.backgroundColor="white";
    a.style.color="black";
    }
    a.setAttribute("num",-t);
    }
    </script>
    </head><body>
    <input type="button" num="1" id="test" style="background-color:#FFF; color:#000" value="test" onclick="change()">
    </body>
    这样试试
      

  2.   

    <!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">
    input.white { background-color:white; }
    input.black { background-color:black; color:white; }
    </style>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
    <script type="text/javascript">
    $(document).ready( function() {
    $("#btn").addClass('white').toggle(function() { $(this).removeClass("white").addClass("black"); }, function() { $(this).removeClass("black").addClass("white"); });
    });
    </script>
    </head><body>
    <input type="button" id="btn" value="我是按钮" />
    </body>
    </html>