日期:2014-05-16 浏览次数:20377 次
<html>
<body>
<table align="center" valign=middle border="0" >
<tr height=48px >
<td width=48px bgcolor="green" id="a1" > </td>
<td width=48px bgcolor="green" id="a2" > </td>
</tr>
</table>
<input type="button" value="change" id="cc" onclick="cc()">
</body>
<script>
function cc()
{
var color=new Array("white","blue","green","orange","red");
document.getElementById("a1").style.backgroundColor=color.splice(parseInt(Math.random()*6-1),1)
document.getElementById("a2").style.backgroundColor=color.splice(parseInt(Math.random()*5-1),1)
}
</script>
</html>
function cc(){
var color=["pink","blue","green","orange","red"].sort(function(){return 0.5 - Math.random()});
color.length=2;
document.getElementById("a1").style.backgroundColor=color[0];
document.getElementById("a2").style.backgroundColor=color[1];
}