第一种写法:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> 获取当前时间 </TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
function time1()
{
var time = new Date();
var hour = time.getHours();
var monutes = time.getMinutes();
var seconds = time.getSeconds();
if(monutes<10)
monutes = "0" + monutes;
if(seconds<10)
seconds = "0" + seconds;
document.write("现在时间:"); //与第二种写法不同的地方
document.getElementById("txtTime").value = hour + ":" + monutes + ":" + seconds;
document.getElementById("txtTime").style.backgroundColor="#accfed";
setTimeout("time1()", 1000);
}
//-->
</SCRIPT>
</HEAD>
<BODY onload="time1()">
现在时间:<INPUT TYPE="text" id="txtTime">
</BODY>
</HTML>
第二种写法:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> 获取当前时间 </TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
function time1()
{
var time = new Date();
var hour = time.getHours();
var monutes = time.getMinutes();
var seconds = time.getSeconds();
if(monutes<10)
monutes = "0" + monutes;
if(seconds<10)
seconds = "0" + seconds;
document.getElementById("txtTime").value = hour + ":" + monutes + ":" + seconds;
document.getElementById("txtTime").style.backgroundColor="#accfed";
setTimeout("time1()", 1000);
}
//-->
</SCRIPT>
</HEAD>
<BODY onload="time1()">
现在时间:<INPUT TYPE="text" id="txtTime">
</BODY>
</HTML>
为什么第一种写法有错误,错误如下:(请尽量详细讲解)