電子書籍の厳選無料作品が豊富!

教えてください。

ページ全体の背景色を変更するのは、
↓でできたのですが、

<form>
<input type="button" value="White" onClick="document.bgColor='white'">
<input type="button" value="Gray" onClick="document.main='gray'">
<input type="button" value="Blue" onClick="document.bgColor='blue'">
</form>

ページ内の一部のテーブルのみの背景色を
変更したい場合はどうように変更すればいいのでしょうか?

教えてください!

A 回答 (3件)

特定の設定を使いまわすなら、cssでclassを


いじる方法もあります。

<style type="text/css">
.white{
background-Color:white;
color:black;
}
.gray{
background-Color:gray;
color:yellow;
}
.blue{
background-Color:blue;
color:red;
}
</style>
<body>
<form>
全体:
<input type="button" value="White" onClick="document.body.className='white'">
<input type="button" value="Gray" onClick="document.body.className='gray'">
<input type="button" value="Blue" onClick="document.body.className='blue'"><br>
テーブル1:
<input type="button" value="White" onClick="document.getElementById('t1').className='white'">
<input type="button" value="Gray" onClick="document.getElementById('t1').className='gray'">
<input type="button" value="Blue" onClick="document.getElementById('t1').className='blue'"><br>
テーブル2:
<input type="button" value="White" onClick="document.getElementById('t2').className='white'">
<input type="button" value="Gray" onClick="document.getElementById('t2').className='gray'">
<input type="button" value="Blue" onClick="document.getElementById('t2').className='blue'"><br>
</form>

<table width=100% id="t1">
<tr><td>test</td></tr>
</table>
<table width=100% id="t2">
<tr><td>test</td></tr>
</table>
</body>
    • good
    • 0
この回答へのお礼

ありがとうございます!
バッチリできましたー!!!

お礼日時:2006/04/03 21:26

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">


<html lang=ja><head>
<script type="text/javascript">
function chClr(id,clr){
clr=clr.toLowerCase();
if(document.getElementById) document.getElementById(id).style.backgroundColor=clr;
else if(document.all) document.all[id].style.backgroundColor=clr;
else if(document.layers) document.layers[id].style.backgroundColor=clr;
else return false;
}
</script>
</head>
<body>
<table border=1><td id="aTd">AAAAAAA</td></table>
<p>
<input type="button" value="Yellow" onclick="chClr('aTd',this.value)">
</p>
</body>
</html>

;-)
    • good
    • 0
この回答へのお礼

こちらの方法でもチャレンジしてみたところ、
できました!
色々な方法があるんですね。

ありがとうございました!

お礼日時:2006/04/03 21:27

あたしなら・・・




<TABLE id=aTable>
・・・
</TABLE>

<INPUT type="button" onclick="document.getElementById('aTable').style.backgroundColor=this.value;" value="white">

位で済ませちゃうけど、コレじゃダメかな?

この回答への補足

ありがとうございます!!!
できました!!

そして、もうひとつ教えていただきたいのですが、
そのテーブル内にあるテキストの文字色も背景色と同タイミングで違う色に変えたい場合は、何を追加したらいいでしょうか?

何度もすみません!
宜しくお願いします!

補足日時:2006/04/03 16:14
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!