为什么以下程序运行会出现错?
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<script type="text/javascript">
window.onload = function(){
function showTime(){
var time = new Date();
time = time.toLocaleString();
document.getElementById("sp_time").innerText = time;
}
window.setInterval('showTime()', 1000);
}
</script>
<span id="sp_time" ></span>
</body>
</html>
将window.onload属性去掉后则可以运行
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<script type="text/javascript">
function showTime() {
var time = new Date();
time = time.toLocaleString();
document.getElementById("sp_time").innerText = time;
}
window.setInterval('showTime()', 1000);
</script>
<span id="sp_time"></span>
</body>
</html>