【サンプル】タグ(文章の)の入れ替え
文章の入れ替えの基本
document.getElementById().innerHTML="";
上記のスクリプトでHTMLタグを置き換える事が出来る。
配列を使うともっと簡単にキレイに出来る。
<script type="text/javascript">
col = new Array();//colと言う名前の空の配列を作る
col[0] = "<img src='image/tuhan0.jpg' width='300' height='300' alt='サンプル' /><p>ここに文章がでます1</p>";
col[1] = "<img src='image/tuhan1.jpg' width='300' height='300' alt='サンプル' /><p>ここに文章がでます2</p>";
col[2] = "<img src='image/tuhan2.jpg' width='300' height='300' alt='サンプル' /><p>ここに文章がでます3</p>";
a = Math.floor(Math.random() * col.length);
document.write(col[a]);
</script>
上記はtest.jsより外部ファイルで表示させています。
functionの呼び出し <script type="text/javascript">change()</script>