
教えてください。
ページ全体の背景色を変更するのは、
↓でできたのですが、
<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>
ページ内の一部のテーブルのみの背景色を
変更したい場合はどうように変更すればいいのでしょうか?
教えてください!
No.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>
No.2
- 回答日時:
<!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>
;-)
No.1
- 回答日時:
あたしなら・・・
<TABLE id=aTable>
・・・
</TABLE>
<INPUT type="button" onclick="document.getElementById('aTable').style.backgroundColor=this.value;" value="white">
位で済ませちゃうけど、コレじゃダメかな?
この回答への補足
ありがとうございます!!!
できました!!
そして、もうひとつ教えていただきたいのですが、
そのテーブル内にあるテキストの文字色も背景色と同タイミングで違う色に変えたい場合は、何を追加したらいいでしょうか?
何度もすみません!
宜しくお願いします!
お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!
このQ&Aを見た人はこんなQ&Aも見ています
関連するカテゴリからQ&Aを探す
おすすめ情報
このQ&Aを見た人がよく見るQ&A
デイリーランキングこのカテゴリの人気デイリーQ&Aランキング
-
javaScriptの変数をJavaの変数...
-
JavaScriptのfileオブジェクト...
-
onchangeイベントを強制的に発...
-
onclickが動作しない
-
fileUploadオブジェクトへの値...
-
<input>の選択肢をプルダウンメ...
-
Selectボックスの幅を自動で広...
-
<JavaScript>tableタグを入力不...
-
ASP.NETでNAME属性を固定にしたい
-
RegularExpressionValidatorの...
-
クリックされた罫表セルの行番...
-
同じ名前のセレクトがある場合...
-
プルダウンで選択された値を別...
-
二次元配列に数字をランダムに...
-
sessionの値でボタンを活性・非...
-
JQueryで2つのテキストフィー...
-
cookie使用時にundefinedと表示...
-
doPostBack 関数について
-
【FORM】 リンク文字で submit...
-
tableの任意行にfocusをあてる
マンスリーランキングこのカテゴリの人気マンスリーQ&Aランキング
-
onchangeイベントを強制的に発...
-
javaScriptの変数をJavaの変数...
-
VB.NETで<Input>タグ、<text...
-
iOSのみダブルタップが必要
-
JavaScriptのfileオブジェクト...
-
追加ボタンを押した際に ok ボ...
-
onClickがinput type="image"だ...
-
innerHTML内では改行は禁止?
-
javascriptでチェックボックス...
-
パラメータから取得した文字をH...
-
クリックさせたいが、click()が...
-
JSPファイルにJavaScriptを埋め...
-
ボタンで配列に代入
-
任意の<DIV></DIV>の中に計算結...
-
javascript教えてください
-
WordpressのCocoonというテーマ...
-
ボタンかリンクをクリックする...
-
HTMLのテキストボックスへのド...
-
onclickが動作しない
-
複数のボタンに対するActionと...
おすすめ情報