<!--季節で背景を変える
function SeasonCahnge(objImg){
myMonth=(new Date()).getMonth();
if(myMonth>=4 && myMonth<6){
//alert(”asdf”);
myIMG=”images/season_1.gif”;
}else if(myMonth>=7 && myMonth<8){
myIMG=”images/season_2.gif”;
}else if(myMonth>=9 && myMonth<11){
myIMG=”images/season_3.gif”;
}else if(myMonth<12 && myMonth>=3){
myIMG=”images/season_4.gif”;
}
objImg.src = myIMG;
}
//-->
</script>
上記スクリプト(間違っていたら教えてください)で画像をテーブルの背景(background)に表示させたいです。いったいどうすればよいでしょう?おしえてください!!
それなら。これでいいかと
<HTML>
</HEAD>
<script language=”JavaScript”>
<!--
//
myMonth=(new Date()).getMonth();
if(myMonth>=4 & myMonth<6){
myIMG=”images/season_2.gif”;
}else if(myMonth>=7 && myMonth<8){
myIMG=”images/season_3.gif”;
}else if(myMonth>=9 && myMonth<11){
myIMG=”images/season_4.gif”;
}else if(myMonth<12 && myMonth>=3){
myIMG=”images/season_1.gif”;
}
document.write(”<BODY BACKGROUND=’”+myIMG+”’>”);
-->
</script>
ホームページ本体
</BODY>
</HTML>
tableの背景とのことなので、以下のソースを背景を変更したいtableの部分に貼付けてみてください。老婆心ですが、季節ごとの背景画像はhtmlと同じ階層の「images」フォルダに、「season_1.gif」〜「season_4.gif」という名前で入れます。
なお、「”」とか「’」が全角になってる場合、すべて半角にしてください。
<script language=”javascript”>
objImg = new Image;
myMonth=(new Date()).getMonth();
if(myMonth>=4 && myMonth<6){
myIMG=”images/season_1.gif”;
}else if(myMonth>=7 && myMonth<8){
myIMG=”images/season_2.gif”;
}else if(myMonth>=9 && myMonth<11){
myIMG=”images/season_3.gif”;
}else if(myMonth<12 && myMonth>=3){
myIMG=”images/season_4.gif”;
}
objImg.src = myIMG;
document.write(”<table background=”+objImg.src+”>”);
</script>
<tr>
<td>
テストテストテストテストテストテストテストテスト
テストテストテストテストテストテストテストテスト
テストテストテストテストテストテストテストテスト
テストテストテストテストテストテストテストテスト
テストテストテストテストテストテストテストテスト
テストテストテストテストテストテストテストテスト
テストテストテストテストテストテストテストテスト
テストテストテストテストテストテストテストテスト
</td>
</tr>
</table>
回答者 | 回答 | 受取 | ベストアンサー | 回答時間 | |
---|---|---|---|---|---|
1 | Noriko | 3回 | 2回 | 0回 | 2004-06-04 18:33:35 |
ありがとうございます。やってみます