首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

简略的时间显示为什么不行

2012-10-19 
简单的时间显示为什么不行?htmlhead/headbodyscript typetext/javascriptvar nownew Date()

简单的时间显示为什么不行?
<html>
<head>


</head>
<body>
<script type="text/javascript">

var now=new Date();

var year=now.getFullYear();
var month=now.getMonth()+1;
var date=now.getDate();

<div style="background-color:blue;width:400px;height:50px">
document.write(year+"年"+month+"月"+date+"日");
</div>
</script>

</body>
</html>
为什么用浏览器打开这个html文件什么也不显示?菜鸟一枚,求教。。。

[解决办法]
<div style="background-color:blue;width:400px;height:50px">
 document.write(year+"年"+month+"月"+date+"日");
</div>
把这个div去掉,就只要 document.write(year+"年"+month+"月"+date+"日");这句,div是html的语句,不要写在script中间。
script之间是不支持这样直接写html代码的。
[解决办法]
没你那么用的.<div style="background-color:blue;width:400px;height:50px">
和</div>你怎么能不做任何处理直接写在script中??

HTML code
<html><head></head><body><script type="text/javascript">var now=new Date();var year=now.getFullYear();var month=now.getMonth()+1;var date=now.getDate();</script><div style="background-color:blue;width:400px;height:50px"><script>document.write(year+"年"+month+"月"+date+"日");</script></div></body></html> 

热点排行