<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>