<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>
<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>
<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">网页的颜色及其值
<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> </td><td>说明</td>
<td width=56> </td><td>说明</td>
<td width=56> </td><td>说明</td>
<td width=56> </td><td>说明</td>
</tr><tr>
<td class=h onclick=color(this.innerText) bgcolor=#FFFFFF>#FFFFFF</td><td> white 纯白色</td>
<td class=h onclick=color(this.innerText) bgcolor=#FF0000>#FF0000</td><td> red 纯红色</td>
<td class=h onclick=color(this.innerText) bgcolor=#00FF00>#00FF00</td><td> lime 纯绿色</td>
<td class=h onclick=color(this.innerText) bgcolor=#0000FF>#0000FF</td><td> blue 纯蓝色</td>
</tr><tr>
<td class=h onclick=color(this.innerText) bgcolor=#000000) style="color: #FFFFFF">#000000</td><td> black 纯黑色</td>
<td class=h onclick=color(this.innerText) bgcolor=#00FFFF>#00FFFF</td><td> cyan 青色</td>
<td class=h onclick=color(this.innerText) bgcolor=#FF00FF>#FF00FF</td><td> Magenta 紫红</td>
<td class=h onclick=color(this.innerText) bgcolor=#FFFF00>#FFFF00</td><td> yellow 纯黄</td>
</tr><tr>
<td class=h onclick=color(this.innerText) bgcolor=#CC3300>#CC3300</td><td> 暗红色</td>
<td class=h onclick=color(this.innerText) bgcolor=#0066CC>#0066CC</td><td> 暗蓝色</td>
<td class=h onclick=color(this.innerText) bgcolor=#FFA500>#FFA500</td><td> orange 桔黄</td>
<td class=h onclick=color(this.innerText) bgcolor=#993399>#993399</td><td> 深紫色</td>
</tr><tr>
<td class=h onclick=color(this.innerText) bgcolor=#99CC00>#99CC00</td><td> 草绿</td>
<td class=h onclick=color(this.innerText) bgcolor=#FF9933>#FF9933</td><td> 橙色</td>
<td class=h onclick=color(this.innerText) bgcolor=#8A2BE2>#8A2BE2</td><td> blueviolet</td>
<td class=h onclick=color(this.innerText) bgcolor=#EE82EE>#EE82EE</td><td> violet</td>
</tr><tr>
<td class=h onclick=color(this.innerText) bgcolor=#FFD700>#FFD700</td><td> gold 黄金色</td>
<td class=h onclick=color(this.innerText) bgcolor=#40E0D0>#40E0D0</td><td> turquoise</td>
<td class=h onclick=color(this.innerText) bgcolor=#ADFF2F>#ADFF2F</td><td> greenyellow</td>
<td class=h onclick=color(this.innerText) bgcolor=#D4D0C8>#D4D0C8</td><td> 系统灰色</td>
</tr><tr>
<td class=h onclick=color(this.innerText) bgcolor=#FF7F50>#FF7F50</td><td> coral</td>
<td class=h onclick=color(this.innerText) bgcolor=#FFFBD0>#FFFBD0</td><td> 极浅黄</td>
<td class=h onclick=color(this.innerText) bgcolor=#CC3300>#CC3300</td><td> 暗红色</td>
<td class=h onclick=color(this.innerText) bgcolor=#99CC00>#99CC00</td><td> 草绿</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>
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>
http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dynstyle/styles.asp
<a href=# onclick="document.body.bgColor = 'green'">方案二</a>
...
</table><table id="myt2">
...
</table>
<script>
myt1.style.backgroundColor = "red";
myt2.style.backgroundColor = "green";
</script>