<script language="javascript">
function mm(a){
var b=document.getElementsByName("btn")
for(var i=0;i<b.length;i++){
if(a==b[i]){
   a.style.background=""
}else{
b[i].style.background="black"
}
}
}
</script>
<input type="button" value="1" name = "btn" onclick="mm(this)" style="background:black">
<input type="button" value="2" name = "btn" onclick="mm(this)" style="background:black">
<input type="button" value="3" name = "btn" onclick="mm(this)" style="background:black">
<input type="button" value="4" name = "btn" onclick="mm(this)" style="background:black">

解决方案 »

  1.   

    <style>
    .black{border:#000000 solid 2px;background-color:#000000;width:100px;height:60px;margin-right:10px;}
    .white{border:#000000 solid 2px;background-color:#FFFFFF;width:100px;height:60px;margin-right:10px;}
    </style>
    <script>
    var old = null;
    function press(obj){
    if(old != null) old.className= "black";
    obj.className="white";
    old = obj;
    }
    </script>
    <span class="black" onclick="press(this)"></span>
    <span class="black" onclick="press(this)"></span>
    <span class="black" onclick="press(this)"></span>
    <span class="black" onclick="press(this)"></span>