随机改变背景颜色

<!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 language="javascript" type="text/javascript">

  function changeBackground()
  {
    //获取到基本颜色
    var color="#"+("00000"+(Math.floor(Math.random()*parseInt("ffffff",16))).toString(16)).substr(-6);
    document.body.style.backgroundColor = color;//改变背景色   
  }
</script>
</head>

<body>
  <p><input id="btn" type="button" value="随机改变背景颜色" onClick="changeBackground()"></p>
</body>
</html>


你可能感兴趣的:(随机颜色)