innerHTMLを使って、リアルタイムに文字列を変更します。
アクセスカウンターの表示や、ジャンプページのカウントダウンなどで使えそうですね。

サンプル

0秒経過

サンプルソース

JavaScript + HTML

<span id="count">0</span>秒経過

<script type="text/javascript">
<!--
	// 変更箇所よりも後にスクリプトを記述するか、OnLoadで呼び出してください 
	var cntup=0;
	var timerId=0;

	function countUp(){
		writeSecond();
		cntup += 1;
		timerId=setTimeout("countUp();",1000);
	}

	function writeSecond(){
		if(document.getElementById){
			document.getElementById("count").innerHTML=cntup;
		} else if(document.all){
			document.all("count").innerHTML=cntup;
		}
	}
//-->
</script>
カテゴリ: JavaScript 2010/04/20 4:37

コメントをどうぞ