这段代码为什么没反应

来源:百度知道 编辑:UC知道 时间:2024/05/17 04:12:02
<script language="javascript">
function clock()
{
var time=new Date();
var second=time.getSeconds();
document.write("<div id=a></div>");
a.innerHTML="<font>"+second+"</font>";
}
setInterval("clock()",1000);
</script>

document.write("<div id=a></div>"); 只是在页面输入一段文本
并不是div元素 你不妨这样写:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script language="javascript">
function clock() {
var time=new Date();
var second=time.getSeconds();
var body1=document.getElementById("body1");
var divTag=document.createElement("div");
body1.appendChild(divTag);
divTag.innerHTML="