为什么这个不对?
<!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=utf-8" />
<title>无标题文档</title>
</head>
<body>
<p id="datefield"> </p>
<script type="text/javascript">
var myDate=new Date();
var dateString=myDate.toLocaleDateString() + " " + myDate.toLocaleTimeString();
var dateLoc=document.getElementById("datafield");
dateLoc.innerHTML="hello:" + dateString;
</script>
</body>
</html>
结果网页是空的,firebug提示:TypeError: dateLoc is null
------解决方案--------------------
老大,你id是错误的,datefield这个是你在<p>里面的id
这个datafield,是你赋值的id。。。