<html>
<body>
<input type="button" value="red" onclick="document.body.bgColor = 'red'">
<input type="button" value="green" onclick="document.body.bgColor = 'green'">
<input type="button" value="image" onclick="document.body.style.backgroundImage = 'url(zip.gif)'">
</body>
</html>

解决方案 »

  1.   

    <html><head>
    <title>网页的颜色及其值</title><meta name="author" content="F.R.Huang">
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <style><!-- td {font-size: 12px} .h{cursor: hand;text-align: center} --></style></head>
    <body leftmargin=0 topmargin=0 bgcolor=blue><br><h2 align=center style="color:000080">网页的颜色及其值
    &nbsp; <input type=text name=bg1 size=7 value="#" onchange="document.bgColor=this.value"></h2>
    <table width=88% border=1 bordercolor=gold cellpadding=2 cellspacing=1 align=center>
    <tr align=center>
    <td width=56>&nbsp;</td><td>说明</td>
    <td width=56>&nbsp;</td><td>说明</td>
    <td width=56>&nbsp;</td><td>说明</td>
    <td width=56>&nbsp;</td><td>说明</td>
    </tr><tr>
    <td class=h onclick=color(this.innerText) bgcolor=#FFFFFF>#FFFFFF</td><td>&nbsp;white 纯白色</td>
    <td class=h onclick=color(this.innerText) bgcolor=#FF0000>#FF0000</td><td>&nbsp;red 纯红色</td>
    <td class=h onclick=color(this.innerText) bgcolor=#00FF00>#00FF00</td><td>&nbsp;lime 纯绿色</td>
    <td class=h onclick=color(this.innerText) bgcolor=#0000FF>#0000FF</td><td>&nbsp;blue 纯蓝色</td>
    </tr><tr>
    <td class=h onclick=color(this.innerText) bgcolor=#000000) style="color: #FFFFFF">#000000</td><td>&nbsp;black 纯黑色</td>
    <td class=h onclick=color(this.innerText) bgcolor=#00FFFF>#00FFFF</td><td>&nbsp;cyan 青色</td>
    <td class=h onclick=color(this.innerText) bgcolor=#FF00FF>#FF00FF</td><td>&nbsp;Magenta 紫红</td>
    <td class=h onclick=color(this.innerText) bgcolor=#FFFF00>#FFFF00</td><td>&nbsp;yellow 纯黄</td>
    </tr><tr>
    <td class=h onclick=color(this.innerText) bgcolor=#CC3300>#CC3300</td><td>&nbsp;暗红色</td>
    <td class=h onclick=color(this.innerText) bgcolor=#0066CC>#0066CC</td><td>&nbsp;暗蓝色</td>
    <td class=h onclick=color(this.innerText) bgcolor=#FFA500>#FFA500</td><td>&nbsp;orange 桔黄</td>
    <td class=h onclick=color(this.innerText) bgcolor=#993399>#993399</td><td>&nbsp;深紫色</td>
    </tr><tr>
    <td class=h onclick=color(this.innerText) bgcolor=#99CC00>#99CC00</td><td>&nbsp;草绿</td>
    <td class=h onclick=color(this.innerText) bgcolor=#FF9933>#FF9933</td><td>&nbsp;橙色</td>
    <td class=h onclick=color(this.innerText) bgcolor=#8A2BE2>#8A2BE2</td><td>&nbsp;blueviolet</td>
    <td class=h onclick=color(this.innerText) bgcolor=#EE82EE>#EE82EE</td><td>&nbsp;violet</td>
    </tr><tr>
    <td class=h onclick=color(this.innerText) bgcolor=#FFD700>#FFD700</td><td>&nbsp;gold 黄金色</td>
    <td class=h onclick=color(this.innerText) bgcolor=#40E0D0>#40E0D0</td><td>&nbsp;turquoise</td>
    <td class=h onclick=color(this.innerText) bgcolor=#ADFF2F>#ADFF2F</td><td>&nbsp;greenyellow</td>
    <td class=h onclick=color(this.innerText) bgcolor=#D4D0C8>#D4D0C8</td><td>&nbsp;系统灰色</td>
    </tr><tr>
    <td class=h onclick=color(this.innerText) bgcolor=#FF7F50>#FF7F50</td><td>&nbsp;coral</td>
    <td class=h onclick=color(this.innerText) bgcolor=#FFFBD0>#FFFBD0</td><td>&nbsp;极浅黄</td>
    <td class=h onclick=color(this.innerText) bgcolor=#CC3300>#CC3300</td><td>&nbsp;暗红色</td>
    <td class=h onclick=color(this.innerText) bgcolor=#99CC00>#99CC00</td><td>&nbsp;草绿</td>
    </tr></tr></table><center><script language="Javascript"><!--
    function color(txt,sty){
    document.all.bg1.value = txt;
    document.bgColor = txt;
    }
    document.writeln("<br><div style='font-size: 12px'>本文档的最后修改时间:"+document.lastModified+"</div>");
    // --></script>
    </center>
    </body></html>
      

  2.   

    一个色阶板<script LANGUAGE="JavaScript">
    var hex = new Array(6)hex[0] = "FF"
    hex[1] = "CC"
    hex[2] = "99"
    hex[3] = "66"
    hex[4] = "33"
    hex[5] = "00"
    function display(triplet) {
    document.bgColor = '#' + triplet
    }
    function drawCell(red, green, blue) {
    document.write('<TD BGCOLOR="#' + red + green + blue + '">')
    document.write('<A HREF="javascript:display(\'' + (red + green + blue) + '\')">')
    document.write('<IMG SRC="place.gif" BORDER=0 HEIGHT=12 WIDTH=12>')
    document.write('</A>')
    document.write('</TD>')
    }
    function drawRow(red, blue) {
    document.write('<TR>')
    for (var i = 0; i < 6; ++i) {
    drawCell(red, hex[i], blue)
    }
    document.write('</TR>')
    }
    function drawTable(blue) {
    document.write('<TABLE CELLPADDING=0 CELLSPACING=0 BORDER=0>')
    for (var i = 0; i < 6; ++i) {
    drawRow(hex[i], blue)
    }
    document.write('</TABLE>')
    }
    function drawCube() {
    document.write('<TABLE CELLPADDING=5 CELLSPACING=0 BORDER=1><TR>')
    for (var i = 0; i < 6; ++i) {
    document.write('<TD BGCOLOR="#FFFFFF">')
    drawTable(hex[i])
    document.write('</TD>')
    }
    document.write('</TR></TABLE>')
    }
    drawCube()
    // -->
    </script>
      

  3.   

    用动态样式:
    http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dynstyle/styles.asp
      

  4.   

    <a href=# onclick="document.body.bgColor = 'red'">方案一</a>
    <a href=# onclick="document.body.bgColor = 'green'">方案二</a>
      

  5.   

    <table id="myt1">
    ...
    </table><table id="myt2">
    ...
    </table>
    <script>
    myt1.style.backgroundColor = "red";
    myt2.style.backgroundColor = "green";
    </script>