JavaScript の質問用スレッド

このエントリーをはてなブックマークに追加
588Name_Not_Found
テキストボックスに時計を表示するときに(これは秒だけになっていますが)
<script type="text/javascript">
&lt;!--

function nowtime(){
now=new Date();
sec=now.getSeconds();
document.forms[0].elements[0].value=sec;
setTimeout('nowtime()'@`1000);
}
//--&gt;
</script>
<body onLoad="nowtime()">
<form>
<input type="textbox">
</form>
</body>
と書くとちゃんと1秒ごとに更新してくれるんですが、
関数の部分を
<script type="text/javascript">
&lt;!--
now=new Date();
sec=now.getSeconds();

function nowtime(){
document.forms[0].elements[0].value=sec;
setTimeout('nowtime()'@`1000);
}
//--&gt;
</script>
<body onLoad="nowtime()">
<form>
<input type="textbox">
</form>
</body>
とするとロードした瞬間の秒をテキストボックスに入力するだけです。
どうしてなんですか?
本には関数の外に書いてある変数は
関数内でも参照できると書いていたんですが。
(長くてすいません)