Math.random()を使用し、テキストをランダムに表示します。

サンプル

このページを更新すると、下記文章がランダムで変更されます。

サンプルソース

JavaScript + CSS

<script type="text/javascript">
<!--
	// ランダムテキスト
	txt = new Array();

	txt[0] = 'おはようございます';
	txt[1] = 'こんにちは';
	txt[2] = 'こんばんは';
	txt[3] = 'おやすみなさい';
	txt[4] = 'おばんです';
	txt[5] = 'おいでやす';

	document.write(txt[(Math.floor(Math.random() * txt.length))]);

//-->
</script>
カテゴリ: JavaScript 2010/04/20 4:02

コメントをどうぞ